shourya90

Untitled

Aug 6th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1.  
  2. #include <YSI\y_va>
  3.  
  4.  
  5. new DCC_Channel:BotChannel;
  6.  
  7. #define DC_CMD:%0(%1,%2) \
  8. forward dc_cmd_%0(%1[],%2[]); \
  9. public dc_cmd_%0(%1[],%2[])
  10.  
  11.  
  12. //CallBacks
  13. forward OnDCCommandPerformed(args[], success);
  14. forward SendDC(channel[], const fmat[], va_args<>);
  15.  
  16. //Functions
  17.  
  18. public SendDC(channel[], const fmat[], va_args<>)
  19. {
  20. new
  21. str[512];
  22. va_format(str, sizeof (str), fmat, va_start<2>);
  23. BotChannel = DCC_FindChannelById(channel);
  24. return DCC_SendChannelMessage(BotChannel, str);
  25. }
  26. /*public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
  27. {
  28. new channel_name[100 + 1];
  29. if(!DCC_GetChannelName(channel, channel_name))
  30. return 0; // invalid channel
  31.  
  32. new user_name[32 + 1];
  33. if (!DCC_GetUserName(author, user_name))
  34. return 0; // invalid user
  35.  
  36. new str[145];
  37. format(str, sizeof str, "[DISCORD]%s: %s", user_name, message);
  38. SendClientMessageToAll(-1, str);
  39. return 1;
  40. }*/
  41. forward DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[]);
  42. public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
  43. {
  44. new channel_name[100 + 1];
  45. if(!DCC_GetChannelName(channel, channel_name))
  46. return 0; // invalid channel
  47.  
  48. new user_name[32 + 1];
  49. if (!DCC_GetUserName(author, user_name))
  50. return 0; // invalid user
  51.  
  52.  
  53. if(!strcmp(user_name, BOT_NAME, true)) return 1;
  54.  
  55. if(!strcmp(channel_name, BOT_CHANNEL, true)) // If user is bot then quit the callback.
  56. {
  57. new dmsg[10][128];
  58. explode(dmsg, message, " ", 2); // Used so we can see if the arguments next to command are empty or have value.
  59.  
  60. new command[20], args[1000];
  61. sscanf(message, "s[20]s[1000]", command, args); // Sperate message in COMMAND and arguments.
  62. if(strfind(command, CMD_PREFIX, true) != -1) // Check if command have prefix defined above.
  63. {
  64. new funcdc[128];
  65. strdel(command, 0, 1);
  66. format(funcdc, sizeof(funcdc), "dc_cmd_%s", command); // Format function.
  67.  
  68. if(isnull(dmsg[1])) {
  69. CallLocalFunction("OnDCCommandPerformed", "si", message, CallLocalFunction(funcdc, "ss", user_name, "\1"));
  70. } else CallLocalFunction("OnDCCommandPerformed", "si", message, CallLocalFunction(funcdc, "ss", user_name, args));
  71.  
  72.  
  73. }
  74. else
  75. {
  76. new str[145];
  77. format(str, sizeof str, "{ff146a}[FROM DISCORD]{FFFFFF}%s: %s", user_name, message);
  78. SendClientMessageToAll(-1, str);
  79. }
  80. }
  81. if(!strcmp(user_name, BOT_NAME_ADMIN, true)) return 1;
  82.  
  83. if(!strcmp(channel_name, BOT_CHANNEL_ADMIN, true)) // If user is bot then quit the callback.
  84. {
  85. new dmsg2[16][128];
  86. explode(dmsg2, message, " ", 2); // Used so we can see if the arguments next to command are empty or have value.
  87.  
  88. new command[20], args[1000];
  89. sscanf(message, "s[20]s[1000]", command, args); // Sperate message in COMMAND and arguments.
  90. if(strfind(command, CMD_PREFIX_ADMIN, true) != -1) // Check if command have prefix defined above.
  91. {
  92. new funcdc[128];
  93. strdel(command, 0, 1);
  94. format(funcdc, sizeof(funcdc), "dc_cmd_%s", command); // Format function.
  95.  
  96. if(isnull(dmsg2[1]))
  97. {
  98. CallLocalFunction("OnDCCommandPerformed", "si", message, CallLocalFunction(funcdc, "ss", user_name, "\1"));
  99. }
  100. else
  101. CallLocalFunction("OnDCCommandPerformed", "si", message, CallLocalFunction(funcdc, "ss", user_name, args));
  102.  
  103.  
  104. }
  105. }
  106. return 1;
  107. }
  108. //Explode
  109. stock explode(aExplode[][], const sSource[], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[])
  110. {
  111. new
  112. iNode,
  113. iPointer,
  114. iPrevious = -1,
  115. iDelimiter = strlen(sDelimiter);
  116.  
  117. while(iNode < iVertices)
  118. {
  119. iPointer = strfind(sSource, sDelimiter, false, iPointer);
  120.  
  121. if(iPointer == -1)
  122. {
  123. strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
  124. break;
  125. }
  126. else
  127. {
  128. strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
  129. }
  130.  
  131. iPrevious = (iPointer += iDelimiter);
  132. ++iNode;
  133. }
  134.  
  135. return iPrevious;
  136. }
Add Comment
Please, Sign In to add comment