[Include] DCC - Discord Command Controller.
#1

DCC - Discord Command Controller

Intro
Hi, As stated above this include is basically discord command controller. Where you can make commands easily just by using DC_CMD:.. like CMD:.., It uses DCC_OnChannelMessage callback to fetch commands. If you do not know about the discord plugin please learn about it first. Click Here and then come back here..

How to?

CallBacks

PHP Code:
forward OnDCCommandPerformed(args[], success);        
forward SendDC(channel[], const fmat[], va_args<>); 
I have added a SendDC callback which sends the message to channel directly without doing the format stuff. It uses y_va so you need it.
PHP Code:
SendDC(CHANNEL_ID"%s has joined the server."name); 
CHANNEL_ID is your Bot channel id which you can change later in script.

The callback
Code:
OnDCCommandPerformed(args[], success)
is called after the command execution if success == 0 means the command is not executed or doesn't exists. For Example,
PHP Code:
public OnDCCommandPerformed(args[], success)
{
    if(!
success) return SendDC(CHANNEL_ID"```js\nInvalid command..!\n```");
    return 
1;

Setting Up
Add That on the top of your script,
PHP Code:
#define CMD_PREFIX "!"
#define BOT_CHANNEL ""
#define BOT_NAME ""
#define CHANNEL_ID "" 
and change it to the way you want. CMD_PREFIX tells which prefix to use like @test or !test and after that include the DCC include.
Code:
#include <dcc>
Adding Commands
Example:
PHP Code:
DC_CMD:m(userargs)
{
     new 
msg[50];
    if(
sscanf(args"s[50]"msg)) return SendDC(CHANNEL_ID""CMD_PREFIX"m [Msg]");
    
SendDC(CHANNEL_ID"%s: %s"usermsg);
    return 
1;

Please report any bug you found or tell me anything u want in this include. I will really Appreciate it.
I have also added the test.pwn to make it more easy for you guys in the rar.

Requirements!
Discord Connector Plugin - https://sampforum.blast.hk/showthread.php?tid=631562
YSI/y_ya.
sscanf2 plugin.
Reply
#2

Awesome!
Reply
#3

Cool
Reply
#4

a substitute to IRC. Nice. Plus Discord is easier to use. +rep.
Reply
#5

[mention]Inn0cent[/mention], is there a way to check if a player uses this role? like for example:
if(PlayerInfo[playerid][DISCORD ROLE])
Reply
#6

Quote:
Originally Posted by SeanDenZYR
View Post
[mention]Inn0cent[/mention], is there a way to check if a player uses this role? like for example:
if(PlayerInfo[playerid][DISCORD ROLE])
No, I haven't added the role thing in this include yet, but i will do so. Btw you can read about roles on Main Plugin Thread.
Reply
#7

Awesome script, too sad not so many communities use discord, neither me myself ;/
Reply
#8

Good job

Quote:
Originally Posted by DeitY
View Post
Awesome script, too sad not so many communities use discord, neither me myself ;/
Jeste jeste xD
Reply
#9

C:\test\pawno\include\dcc.inc(37) : error 017: undefined symbol "BOT_NAME"
C:\test\pawno\include\dcc.inc(39) : error 017: undefined symbol "BOT_CHANNEL"
C:\test\pawno\include\dcc.inc(46) : error 017: undefined symbol "CMD_PREFIX"
Reply
#10

Awesome work i will test this.
Reply
#11

Brilliant, who the fuck keeps rating every thread 1 star lmfao!
Good job tho.
Reply
#12

I'm a bit confused.. is this for players from discord typing /command, or just a command parser from ingame that outputs to discord?
Reply
#13

Quote:
Originally Posted by Chaprnks
Посмотреть сообщение
I'm a bit confused.. is this for players from discord typing /command, or just a command parser from ingame that outputs to discord?
I'm also a bit confused. Little help?
Reply
#14

Beauty. Gonna implement asap!
Reply
#15

Quote:
Originally Posted by Infin1ty
Посмотреть сообщение
Код:
#define CMD_PREFIX "!" 
#define BOT_CHANNEL "" 
#define BOT_NAME "" 
#define CHANNEL_ID ""
Put these before include <dcc>
Reply
#16

winrar is damaged please fix it
Reply
#17

Quote:
Originally Posted by Chaprnks
Посмотреть сообщение
I'm a bit confused.. is this for players from discord typing /command, or just a command parser from ingame that outputs to discord?
^ me too
Reply
#18

when i type the commands in server or in discord channel it not gives me the syntax and also the cmds not works
Reply
#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
#20

I know this is a kinda old thread but this is important, I want to know if you had added a staff/role check as yet because this would be handed for me right now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)