maddinat0r / samp-discord-connector

SA:MP plugin which controls a Discord bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

0.3.6-pre command and DCC_OnMessageCreate issue

karimcambridge opened this issue · comments

image

See the image. The bot just always responds with jessica is thinking.


	public DCC_OnMessageCreate(DCC_Message:message)
	{
		new
			messageContent[144]
		;
		DCC_GetMessageContent(message, messageContent);
		printf("DCC_OnMessageCreate, %s", messageContent);
		return 1;
	}

messageContent is always empty.

Well how are you using it? That snippet is irrelevant.
Commands are not handled via messages, they have their own callback in DCC_CreateCommand that will be called.

Well how are you using it? That snippet is irrelevant. Commands are not handled via messages, they have their own callback in DCC_CreateCommand that will be called.

Sorry, it's 2 bugs. The title didn't update.

The snippet is relevant, for some reason the message in DCC_OnMessageCreate is always empty.

For the commands

#define DCMD:%1(%2)	\
		forward dccmd_%1(%2);	\
		public dccmd_%1(%2)

connectDiscord()
	{
		print("[SYSTEM:: connectDiscord]: Initializing.");
		discordKCNRGuild = DCC_FindGuildById("194650354283970560");

		print("[SYSTEM:: connectDiscord]: Channels & roles setup.");

		DCC_CreateCommand("serverip", "KCNR SAMP - Get's the server ip", "dccmd_serverip", false, discordKCNRGuild);
	}

DCMD:serverip(DCC_Channel:channel, DCC_User:author, params[])
	{
		#if DUAL_SERVER_MODE == (true)
			DCC_SendChannelMessage(channel, "**The Server 1**: "#SERVER_IP_DOMAIN". **Server 2**: "#SERVER_IP_DOMAIN_2""); // (Alt: "#SERVER_IP_ADDRESS")
		#else
			DCC_SendChannelMessage(channel, "**Server IP**: "#SERVER_IP_DOMAIN".");
		#endif
		return 1;
	}

You shouldn't be using any variation of "command processors" for proper discord slash commands. That's handled in the plugin, see: https://gist.github.com/Alasnkz/0a6b8149fe9e29c910a3559552afa891
Message content being empty is an intent issue due to discord adding a new value in 2022, that'll be fixed shortly.

I've been testing this new plugin option to handle commands, by chance can the arguments also be made in the future? (I saw that you didn't enable the DCC_Option:DCC_AddCommandOption)

Very unlikely. Adapting such a thing into pawn is very hard, you need to think about how you would even get the arguments across into pawn in a less-confusing way.

I'd rather you just use sscanf and parse it yourself.

it would be possible for example, you put an extra parameter in CreateCommand to specify the parameters as an array, example

new Arguments[][] = {"arg1", "arg2"};
DCC_CreateCommand("command1", "description", "Callback", Arguments, false);
DCC_CreateCommand("command2", "description", "Callback", _, false);

Because this way I liked it a lot, the commands are listed by the discord itself when using '/' and clicking on the bot.

Now in the return callback, I believe that it would be difficult to pass these optional parameters, so I think that with sscanf it would be the best way to separate the command arguments.

commented

I think it would also be possible to use the same Embed, for example: DCC_AddEmbedField(DCC_Embed:embed, const name[], const value[], bool:inline = false); which would be something like this DCC_AddCommandOption(DCC_Command:command, type, const name[], const description[], ...);