[Include] DCC - Discord Command Controller.
#19

Quote:
Originally Posted by CaptainBoi
Посмотреть сообщение
when i type the commands in server or in discord channel it not gives me the syntax and also the cmds not works
I modified it a bit, it works fine for me:

Added SendDCByName
and fixed a crash where if you type % in the discord chat and output it into server, it would crash while processing.
Also added multi channel support, you can sendcbyname and check the channel name on channel cmd performed, added a channel parameter in DCCMD: and blah

Код:
#include <sscanf2>
#include <YSI\y_va>
#include <discord-connector>

new DCC_Channel:BotChannel;

#define DC_CMD:%0(%1,%2,%3)          \
			forward dc_cmd_%0(%1[],%2[],%3[]); \
			public dc_cmd_%0(%1[],%2[],%3[])

			
//CallBacks
forward OnDCCommandPerformed(args[], success, channel[]);		
forward SendDC(channel[], const fmat[], va_args<>);
forward SendDCByName(channel[], const fmat[], va_args<>);

//Functions

public SendDC(channel[], const fmat[], va_args<>)
{
    new
        str[145];
    va_format(str, sizeof (str), fmat, va_start<2>);
	BotChannel = DCC_FindChannelById(channel);
    return DCC_SendChannelMessage(BotChannel, str);
}
public SendDCByName(channel[], const fmat[], va_args<>)
{
    new
        str[145];
    va_format(str, sizeof (str), fmat, va_start<2>);
	BotChannel = DCC_FindChannelByName(channel);
    return DCC_SendChannelMessage(BotChannel, str);
}
//CommandsSection
public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
{
	new channel_name[100 + 1];
	if(!DCC_GetChannelName(channel, channel_name))
		return 0; // invalid channel

	new user_name[32 + 1];
	if (!DCC_GetUserName(author, user_name))
		return 0; // invalid user
	
	new msgFx[1024];
	format(msgFx, 1024, message);
	for(new s; s < strlen(msgFx); s++)
	{
		if (msgFx[s] == '%')
		{
			msgFx[s] = ' ';
		}
	}
		
	if(!strcmp(user_name, BOT_NAME, true)) return 1;
	
	if(strlen(user_name) > 0) // If user is bot then quit the callback.
	{
		new dmsg[10][128];
		explode(dmsg, msgFx, " ", 2); // Used so we can see if the arguments next to command are empty or have value.
		new command[10], args[50];
		sscanf(msgFx, "s[10]s[50]", command, args); // Sperate message in COMMAND and arguments.
		if(strfind(command, CMD_PREFIX, true) != -1) // Check if command have prefix defined above.
		{
			new funcdc[128];
			strdel(command, 0, 1);
			format(funcdc, sizeof(funcdc), "dc_cmd_%s", command); // Format function.
			
			if(isnull(dmsg[1])) {
				CallLocalFunction("OnDCCommandPerformed", "sis", msgFx, CallLocalFunction(funcdc, "sss", user_name, "\1", channel_name), channel_name);
			} else CallLocalFunction("OnDCCommandPerformed", "sis", msgFx, CallLocalFunction(funcdc, "sss", user_name, args, channel_name), channel_name);
				
			
		}
	}
	return 1;
}
//Explode
stock explode(aExplode[][], const sSource[], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[])
{
	new
		iNode,
		iPointer,
		iPrevious = -1,
		iDelimiter = strlen(sDelimiter);

	while(iNode < iVertices)
	{
		iPointer = strfind(sSource, sDelimiter, false, iPointer);

		if(iPointer == -1)
		{
			strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
			break;
		}
		else
		{
			strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
		}

		iPrevious = (iPointer += iDelimiter);
		++iNode;
	}

	return iPrevious;
}
Can be used with multiple channels and blah blah.
Example:
Код:
DC_CMD:ban(author, params, channel)
{
	if(strcmp(channel, "staff-bot")) return SendDCByName(CHANNEL_ALL_NAME, "```css\nERROR: You are not allowed to use this command!```");
	new target, reason[128], hours;
	if(sscanf(params, "uds[127]", target, hours, reason)) return SendDCByName(CHANNEL_STAFF_NAME, "```css\nUSAGE: ban [playerid] [hours] [reason]```");
	if(hours < 1 || hours > 8760) return SendDCByName(CHANNEL_STAFF_NAME, "```css\nBan time cannot be less than 1 or more than 8760 hours!```");
	if(!IsPlayerConnected(target)) return SendDCByName(CHANNEL_STAFF_NAME, "```css\nERROR: Target is not connected```");
   
	BanPlayer(sprintf("[DISCORD ADMIN] %s", author), target, reason, false, hours, false);
	if(PlayerInfo[target][LoggedIn] == true) AddToAdminRecord(target, sprintf("Banned by %s [DISCORD] for %s.", author, reason));
    SendDCByName(CHANNEL_STAFF_NAME, "```css\nTarget banned```");
	return 1;
}
Код:
#if defined DISCORD_PLUGIN
#include <discord-connector>
#define BOT_NAME "botnamehere" // Btw this is used so the bot skips its own messages so if the bot would send !kick it would detect the command but skips it because its the bot itself.
#define CHANNEL_STAFF_NAME "staff-bot"
#define CHANNEL_ALL_NAME "ingame-bot"
#define CMD_PREFIX "!"
#include <dcc>
#endif
Added SendDCByName (ids are quite a pain to work with if you recreate channels to clear all logs like me)

Код:
public OnDCCommandPerformed(args[], success, channel[])
{
    SendDCByName(channel, "```css\nYou sent the command '%s'```", args);
    return 1;
}
Reply


Messages In This Thread
DCC - Discord Command Controller. - by Inn0cent - 24.12.2017, 20:54
Re: DCC - Discord Command Controller. - by Barnwell - 24.12.2017, 21:10
Re: DCC - Discord Command Controller. - by StrikerZ - 25.12.2017, 04:30
Re: DCC - Discord Command Controller. - by SeanDenZYR - 18.01.2018, 11:52
Re: DCC - Discord Command Controller. - by SeanDenZYR - 18.01.2018, 13:11
Re: DCC - Discord Command Controller. - by Inn0cent - 18.01.2018, 13:46
Re: DCC - Discord Command Controller. - by DeitY - 19.01.2018, 10:20
Re: DCC - Discord Command Controller. - by Unkovic - 29.01.2018, 10:08
Re: DCC - Discord Command Controller. - by waysemir - 22.02.2018, 17:28
Re: DCC - Discord Command Controller. - by N0FeaR - 22.02.2018, 17:31
Re: DCC - Discord Command Controller. - by RogueDrifter - 23.02.2018, 15:17
Re: DCC - Discord Command Controller. - by Chaprnks - 24.02.2018, 04:17
Re: DCC - Discord Command Controller. - by Exhibit - 11.04.2018, 14:40
Re: DCC - Discord Command Controller. - by DeitY - 11.04.2018, 19:34
Re: DCC - Discord Command Controller. - by Exhibit - 11.04.2018, 23:18
Re: DCC - Discord Command Controller. - by ZigGamerx - 17.08.2018, 07:36
Re: DCC - Discord Command Controller. - by AzaMx - 18.08.2018, 06:46
Re: DCC - Discord Command Controller. - by CaptainBoi - 18.08.2018, 07:00
Re: DCC - Discord Command Controller. - by MafiaOink - 18.08.2018, 09:11
Re: DCC - Discord Command Controller. - by Leaky - 08.11.2018, 04:35
Re: DCC - Discord Command Controller. - by CJ101 - 12.11.2018, 21:23
Re: DCC - Discord Command Controller. - by TommyB - 13.11.2018, 01:35
Re: DCC - Discord Command Controller. - by KaliDobrev - 05.02.2019, 14:27
Re: DCC - Discord Command Controller. - by FransSacco - 06.03.2019, 15:21

Forum Jump:


Users browsing this thread: 3 Guest(s)