Advertisement
Guest User

Discord Command Processor for SA-MP

a guest
Jul 25th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.87 KB | None | 0 0
  1. #include <sscanf2>
  2. #include <YSI\y_va>
  3. #include <discord-connector>
  4.  
  5.  
  6. #define DISCORD     DCCMD
  7. #define DC_CMD      DCCMD
  8. #define SendDC      SendDiscordMessage
  9. #define DCCMD:%0(%1,%2)          \
  10.             forward dc_cmd_%0(%1,%2[]); \
  11.             public dc_cmd_%0(%1,%2[])
  12.            
  13. forward OnDCCommandPerformed(args[], success)
  14.  
  15. //Discord Channel Callback
  16. new DCC_Channel:g_Discord_Command_Place;
  17. new DCC_Channel:BotChannel;
  18.  
  19. forward SendDiscordMessage(channel[], const fmat[], va_args<>);
  20. public SendDiscordMessage(channel[], const fmat[], va_args<>)
  21. {
  22.     new
  23.         str[145];
  24.     va_format(str, sizeof (str), fmat, va_start<2>);
  25.     BotChannel = DCC_FindChannelById(channel);
  26.     return DCC_SendChannelMessage(BotChannel, str);
  27. }
  28.  
  29. forward DCC_OnMessageCreate(DCC_Message:message);
  30. public DCC_OnMessageCreate(DCC_Message:message)
  31. {
  32.     new realMsg[100];
  33.     DCC_GetMessageContent(message, realMsg, 100);
  34.     new bool:IsBot;
  35.     new DCC_Channel:channel;
  36.     DCC_GetMessageChannel(message, channel);
  37.     new DCC_User:author;
  38.     DCC_GetMessageAuthor(message, author);
  39.     DCC_IsUserBot(author, IsBot);
  40.     g_Discord_Command_Place = DCC_FindChannelById(DISCORD_CHANNEL_ID);
  41.     if(channel == g_Discord_Command_Place && !IsBot) //!IsBot will block BOT's message in discord like (Bot A : /ban 1 test")
  42.     {
  43.         new dmsg[10][128];
  44.         explode(dmsg, realMsg, " ", 2);
  45.         new command[10], args[50];
  46.         sscanf(realMsg, "s[10]s[50]", command, args); // Sperate message in COMMAND and arguments.
  47.         if(strfind(command, DISCORD_PREFIX, true) != -1) // Check if command have prefix defined above.
  48.         {
  49.             new funcdc[128];
  50.             strdel(command, 0, 1);
  51.             format(funcdc, sizeof(funcdc), "dc_cmd_%s", command); // Format function.
  52.            
  53.             if(isnull(dmsg[1])) {
  54.                 CallLocalFunction("OnDCCommandPerformed", "si", realMsg, CallLocalFunction(funcdc, "is", _: author, "\1"));
  55.             } else CallLocalFunction("OnDCCommandPerformed", "si", realMsg, CallLocalFunction(funcdc, "is", _: author, args));
  56.         }
  57.     }
  58.  
  59.     return 1;
  60. }
  61.  
  62. stock explode(aExplode[][], const sSource[], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[])
  63. {
  64.     new
  65.         iNode,
  66.         iPointer,
  67.         iPrevious = -1,
  68.         iDelimiter = strlen(sDelimiter);
  69.  
  70.     while(iNode < iVertices)
  71.     {
  72.         iPointer = strfind(sSource, sDelimiter, false, iPointer);
  73.  
  74.         if(iPointer == -1)
  75.         {
  76.             strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
  77.             break;
  78.         }
  79.         else
  80.         {
  81.             strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
  82.         }
  83.  
  84.         iPrevious = (iPointer += iDelimiter);
  85.         ++iNode;
  86.     }
  87.  
  88.     return iPrevious;
  89. }
  90.  
  91. stock GetDiscordName(DCC_User:user)
  92. {
  93.     new pname_[32];
  94.     DCC_GetUserName(user, pname_);
  95.     return pname_;
  96. }
  97.  
  98. stock UserHasRole(DCC_User:user, DCC_Role:role)
  99. {
  100.     new bool:value;
  101.     new DCC_Guild:jGuild = DCC_FindGuildById(GUILD_ID);
  102.     DCC_HasGuildMemberRole(jGuild, user, role, value);
  103.     return value;
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement