Guest User

Shabby IRC bot.

a guest
Nov 29th, 2011
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.70 KB | None | 0 0
  1. #include <a_samp>
  2. #include <mysql>
  3. #include <irc>
  4. #include <sscanf2>
  5. #include <ServerQuery>
  6. #include <a_http>
  7.  
  8. #define CMD(%1) IRCCMD:%1(botid,channel[],user[],host[],params[])//these dont need "" marks
  9. #define AI(%1) if(!strcmp(message,%1,true))// these need to be in "" marks
  10. #define IsOwner !strcmp(host,"ident@host")
  11.  
  12. #define BOT_1_NICKNAME "" // Name that everyone will see
  13. #define BOT_1_REALNAME "" // Name that will only be visible in a whois
  14. #define BOT_1_USERNAME "" // Name that will be in front of the hostname (username@hostname)
  15.  
  16. #define IRC_SERVER "irc.tl"
  17. #define IRC_PORT (6667)
  18. #define IRC_CHANNEL ""
  19.  
  20. #define IRC_BOT_PASSWORD "" // Put a password here.
  21.  
  22. // Maximum number of bots in the filterscript
  23. #define MAX_BOTS (100)
  24.  
  25. //Mysql
  26. #define MYSQL_HOST "localhost"
  27. #define MYSQL_USER "root"
  28. #define MYSQL_PASS ""
  29. #define MYSQL_DB ""
  30.  
  31. #define systemv "2.5.6"
  32.  
  33. #define Loop(%0,%1) \
  34. for(new %0; %0 != %1; %0++)
  35.  
  36. new starttime;
  37.  
  38. new
  39. gBotID[MAX_BOTS],
  40. gGroupID;
  41.  
  42. new CopyMe = 0;
  43.  
  44. new DotReplace = 0;
  45.  
  46. //new Registering = 0;
  47. //new UserToRegister;
  48.  
  49. main()
  50. {
  51. print("+==========================================+");
  52. print("| |");
  53. print("| Starting Shabby By Shabeer |");
  54. print("| |");
  55. print("+==========================================+");
  56. }
  57.  
  58. public OnGameModeInit()
  59. {
  60. mysql_start();//Connect to Mysql
  61. SetTimerEx("IRC_ConnectDelay", 100, 0, "d", 1);// Wait 2 seconds for the first bot
  62. SetTimer("Sendrand", 70000, true);
  63. SetTimer("LCSUpdate",600000,1);
  64. gGroupID = IRC_CreateGroup();// Create a group (the bots will be added to it upon connect)
  65. return 1;
  66. }
  67.  
  68. public OnGameModeExit()
  69. {
  70. mysql_close();//close Mysql
  71. IRC_Quit(gBotID[0], "Good Bye!"); // Disconnect the first bot
  72. IRC_DestroyGroup(gGroupID);// Destroy the group
  73. return 1;
  74. }
  75.  
  76. forward RestartGM();
  77. public RestartGM()
  78. {
  79. SendRconCommand("gmx");
  80. }
  81.  
  82.  
  83. // Using this you can make your bot talk randomly.
  84.  
  85. /*new SAYRAND[][] =
  86. {
  87. "msg 1",
  88. "msg 2",
  89. "msg 3"
  90. "so on....."
  91. };
  92.  
  93. forward Sendrand();
  94. public Sendrand()
  95. {
  96. new randMSG = random(sizeof(SAYRAND));
  97. IRC_Say(gBotID[0], "#channel", SAYRAND[randMSG]);
  98. }*/
  99.  
  100. //Mysql
  101.  
  102. forward AutoJoinChannels(botid);
  103. public AutoJoinChannels(botid)
  104. {
  105. new
  106. string[ 128 ], data[ 256 ];
  107.  
  108. mysql_query("SELECT * FROM `autojoin`");
  109.  
  110. mysql_store_result();
  111.  
  112. if (mysql_num_rows() > 0)
  113. {
  114. new count = 0;
  115.  
  116. while(mysql_fetch_row(data))
  117. {
  118. mysql_fetch_field("channel",data);
  119.  
  120. IRC_JoinChannel(botid, data);
  121.  
  122. printf("Channel: %s", data);
  123.  
  124. count++;
  125. }
  126.  
  127. format(string, sizeof( string ), " 12* Version: %s", systemv);
  128. IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
  129.  
  130. if(!mysql_ping())
  131. {
  132. IRC_GroupSay(gGroupID, IRC_CHANNEL, "10* My7SQL: Connection is alive!");
  133. }
  134. else
  135. {
  136. IRC_GroupSay(gGroupID, IRC_CHANNEL, "10* My7SQL: Connection is dead!");
  137. }
  138.  
  139. format(string, sizeof( string ), "13* Auto-Join: %d auto-join channels saved.", count);
  140. IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
  141.  
  142. format(string, sizeof( string ), "11* Admins: I've %d admin(s).", CountTotalAdmins());
  143. IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
  144.  
  145. format(string, sizeof( string ), "14* Plugins: Currently 4 plugins are loaded.");
  146. IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
  147. }
  148. mysql_free_result();
  149. }
  150.  
  151. forward mysql_start();
  152. public mysql_start()
  153. {
  154. new MySQL:connection = mysql_init(LOG_ONLY_ERRORS, 1);
  155.  
  156. if (mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, connection))
  157. {
  158. print("+================================+");
  159. print("| |");
  160. print("| [MYSQL] Connection successful! |");
  161. print("| |");
  162. print("+================================+");
  163. }
  164. else
  165. {
  166. print("[MYSQL] There was an error connecting to the MYSQL server. Shit!");
  167. }
  168. return 1;
  169. }
  170.  
  171. forward CheckSQL();
  172. public CheckSQL()
  173. {
  174. new bool:connected;
  175.  
  176. if (mysql_ping() != 0)
  177. {
  178. connected = false;
  179. }
  180. else
  181. {
  182. connected = true;
  183. }
  184.  
  185. if (connected == false)
  186. {
  187. print("[MYSQL] Lost connection to MYSQL server, Reconnecting...");
  188.  
  189. mysql_start();
  190. }
  191.  
  192. return 1;
  193. }
  194.  
  195. forward SendQuery(query[]);
  196. public SendQuery(query[])
  197. {
  198. CheckSQL();
  199.  
  200. if (mysql_query(query))
  201. {
  202. //printf("[MYSQL] MySQL query successful. (%s)", query);
  203. //printf("[MYSQL] MySQL query successful.");
  204. }
  205. else
  206. {
  207. //printf("[MYSQL] MySQL query unsuccessful. (%s)", query);
  208. //printf("[MYSQL] MySQL query unsuccessful.");
  209. return false;
  210. }
  211.  
  212. return 1;
  213. }
  214.  
  215. //IRC Publics
  216.  
  217. public IRC_OnConnect(botid)
  218. {
  219. IRC_AddToGroup(gGroupID, botid);
  220. printf("*** IRC_OnConnect: Bot ID %d connected!", botid);
  221. AutoJoinChannels(botid);
  222. starttime = gettime();
  223. return 1;
  224. }
  225.  
  226. public IRC_OnDisconnect(botid)
  227. {
  228. printf("*** IRC_OnDisconnect: Bot ID %d disconnected!", botid);
  229. if (botid == gBotID[0])
  230. {
  231. gBotID[0] = 0;
  232. SetTimerEx("IRC_ConnectDelay", 10000, 0, "d", 1);
  233. }
  234. printf("*** IRC_OnDisconnect: Bot ID %d attempting to reconnect...", botid);
  235. // Remove the bot from the group
  236. IRC_RemoveFromGroup(gGroupID, botid);
  237. return 1;
  238. }
  239.  
  240. forward IRC_ConnectDelay(tempid);
  241. public IRC_ConnectDelay(tempid)
  242. {
  243. switch (tempid)
  244. {
  245. case 1:
  246. {
  247. // Connect the first bot
  248. gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
  249. }
  250. /*
  251. case 2:
  252. {
  253. // Connect the second bot
  254. gBotID[1] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_2_NICKNAME, BOT_2_REALNAME, BOT_2_USERNAME);
  255. }
  256. */
  257. }
  258. return 1;
  259. }
  260.  
  261. /*
  262. This callback is executed whenever a connection attempt begins. IRC_Quit may
  263. be called at any time to stop the reconnection process.
  264. */
  265.  
  266. public IRC_OnConnectAttempt(botid, ip[], port)
  267. {
  268. printf("*** IRC_OnConnectAttempt: Bot ID %d attempting to connect to %s:%d...", botid, ip, port);
  269. return 1;
  270. }
  271.  
  272. /*
  273. This callback is executed whenever a connection attempt fails. IRC_Quit may
  274. be called at any time to stop the reconnection process.
  275. */
  276.  
  277. public IRC_OnConnectAttemptFail(botid, ip[], port, reason[])
  278. {
  279. printf("*** IRC_OnConnectAttemptFail: Bot ID %d failed to connect to %s:%d (%s)", botid, ip, port, reason);
  280. return 1;
  281. }
  282.  
  283. /*
  284. This callback is executed whenever a bot joins a channel.
  285. */
  286.  
  287. public IRC_OnJoinChannel(botid, channel[])
  288. {
  289. printf("*** IRC_OnJoinChannel: Bot ID %d joined channel %s", botid, channel);
  290. return 1;
  291. }
  292.  
  293. /*
  294. This callback is executed whenevever a bot leaves a channel.
  295. */
  296.  
  297. public IRC_OnLeaveChannel(botid, channel[], message[])
  298. {
  299. printf("*** IRC_OnLeaveChannel: Bot ID %d left channel %s (%s)", botid, channel, message);
  300. IRC_JoinChannel(botid, channel);
  301. return 1;
  302. }
  303.  
  304. /*
  305. This callback is executed whenevever a bot is kicked from a channel. If the
  306. bot cannot immediately rejoin the channel (in the event, for example, that
  307. the bot is kicked and then banned), you might want to set up a timer here
  308. for rejoin attempts.
  309. */
  310.  
  311. public IRC_OnKickedFromChannel(botid, channel[], oppeduser[], oppedhost[], message[])
  312. {
  313. printf("*** IRC_OnKickedFromChannel: Bot ID %d kicked by %s (%s) from channel %s (%s)", botid, oppeduser, oppedhost, channel, message);
  314. IRC_JoinChannel(botid, channel);
  315. return 1;
  316. }
  317.  
  318. public IRC_OnUserDisconnect(botid, user[], host[], message[])
  319. {
  320. printf("*** IRC_OnUserDisconnect (Bot ID %d): User %s (%s) disconnected (%s)", botid, user, host, message);
  321. return 1;
  322. }
  323.  
  324. public IRC_OnUserJoinChannel(botid, channel[], user[], host[])
  325. {
  326. printf("*** IRC_OnUserJoinChannel (Bot ID %d): User %s (%s) joined channel %s", botid, user, host, channel);
  327. return 1;
  328. }
  329.  
  330. public IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[])
  331. {
  332. printf("*** IRC_OnUserLeaveChannel (Bot ID %d): User %s (%s) left channel %s (%s)", botid, user, host, channel, message);
  333. return 1;
  334. }
  335.  
  336. public IRC_OnUserKickedFromChannel(botid, channel[], kickeduser[], oppeduser[], oppedhost[], message[])
  337. {
  338. printf("*** IRC_OnUserKickedFromChannel (Bot ID %d): User %s kicked by %s (%s) from channel %s (%s)", botid, kickeduser, oppeduser, oppedhost, channel, message);
  339. }
  340.  
  341. public IRC_OnUserNickChange(botid, oldnick[], newnick[], host[])
  342. {
  343. printf("*** IRC_OnUserNickChange (Bot ID %d): User %s (%s) changed his/her nick to %s", botid, oldnick, host, newnick);
  344. return 1;
  345. }
  346.  
  347. public IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[])
  348. {
  349. printf("*** IRC_OnUserSetChannelMode (Bot ID %d): User %s (%s) on %s set mode: %s", botid, user, host, channel, mode);
  350. return 1;
  351. }
  352.  
  353. public IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[])
  354. {
  355. printf("*** IRC_OnUserSetChannelTopic (Bot ID %d): User %s (%s) on %s set topic: %s", botid, user, host, channel, topic);
  356. return 1;
  357. }
  358.  
  359. public IRC_OnUserNotice(botid, recipient[], user[], host[], message[])
  360. {
  361. printf("*** IRC_OnUserNotice (Bot ID %d): User %s (%s) sent notice to %s: %s", botid, user, host, recipient, message);
  362. // Someone sent the second bot a notice (probably a network service)
  363. if (!strcmp(recipient, BOT_1_NICKNAME))
  364. {
  365. IRC_Notice(botid, user, "Why did you send me a notice?");
  366. }
  367. return 1;
  368. }
  369.  
  370. public IRC_OnUserRequestCTCP(botid, user[], host[], message[])
  371. {
  372. printf("*** IRC_OnUserRequestCTCP (Bot ID %d): User %s (%s) sent CTCP request: %s", botid, user, host, message);
  373. // Someone sent a CTCP VERSION request
  374. if (!strcmp(message, "VERSION"))
  375. {
  376. IRC_ReplyCTCP(botid, user, "version Shabby 1.0 - Shabeer; http://shabeer.us");
  377. }
  378. return 1;
  379. }
  380.  
  381. public IRC_OnUserReplyCTCP(botid, user[], host[], message[])
  382. {
  383. printf("*** IRC_OnUserReplyCTCP (Bot ID %d): User %s (%s) sent CTCP reply: %s", botid, user, host, message);
  384. return 1;
  385. }
  386.  
  387. /*
  388. This callback is useful for logging, debugging, or catching error messages
  389. sent by the IRC server.
  390. */
  391.  
  392. public IRC_OnReceiveRaw(botid, message[])
  393. {
  394. new File:file;
  395. if (!fexist("irc_log.txt"))
  396. {
  397. file = fopen("irc_log.txt", io_write);
  398. }
  399. else
  400. {
  401. file = fopen("irc_log.txt", io_append);
  402. }
  403. if (file)
  404. {
  405. fwrite(file, message);
  406. fwrite(file, "\r\n");
  407. fclose(file);
  408. }
  409. return 1;
  410. }
  411.  
  412. public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
  413. {
  414. printf("*** IRC_OnUserSay (Bot ID %d): User %s (%s) sent message to %s: %s", botid, user, host, recipient, message);
  415. // Someone sent the first bot a private message
  416.  
  417. if (DotReplace == 1)
  418. {
  419. new string[500];
  420. format(string, sizeof(string), "%s", str_replace(".", "DOT", message));
  421. IRC_GroupSay(gGroupID, recipient, string);
  422. }
  423.  
  424. if (CopyMe == 1)
  425. {
  426. IRC_GroupSay(gGroupID, recipient, message);
  427. }
  428. return 1;
  429. }
  430.  
  431. IRCCMD:serverinfo(botid, channel[], user[], host[], params[])
  432. {
  433. //IRC_GroupSay(gGroupID, channel, "its ok (1)");
  434. new ip[32], port;
  435. //IRC_GroupSay(gGroupID, channel, "its ok (2)");
  436. if(sscanf(params, "p<:>s[32]i", ip, port)) return IRC_GroupSay(gGroupID, channel, "4Error: !serverinfo <ip> <port>");
  437. //IRC_GroupSay(gGroupID, channel, "its ok (3)");
  438. if(GetInfoPacket(ip, port))
  439. {
  440. //IRC_GroupSay(gGroupID, channel, "its ok (4)");
  441. new string[256], hostname[75], gamemode[45], mapname[35],SQplayers;
  442. //IRC_GroupSay(gGroupID, channel, "its ok (5)");
  443. iGetHostname(hostname);
  444. //IRC_GroupSay(gGroupID, channel, "its ok (6)");
  445. iGetGamemode(gamemode);
  446. //IRC_GroupSay(gGroupID, channel, "its ok (7)");
  447. iGetMapname(mapname);
  448. //IRC_GroupSay(gGroupID, channel, "its ok (8)");
  449. SQplayers = iGetPlayers();
  450. //IRC_GroupSay(gGroupID, channel, "its ok (9)");
  451. format(string,sizeof string,"02 %s 03Gamemode: %s 04Map: %s 06Players: %d/%d 13Passworded: %d",hostname,gamemode,mapname,SQplayers,iGetMaxPlayers(),iIsPassworded());
  452. //IRC_GroupSay(gGroupID, channel, "its ok (10)");
  453. IRC_GroupSay(gGroupID, channel, string);
  454. //IRC_GroupSay(gGroupID, channel, "its ok (11)");
  455. //format(string,sizeof string,"%d Players, GM: %s, Mapname: %s",SQplayers,gamemode,mapname);
  456. //IRC_GroupSay(gGroupID, channel, "its ok (12)");
  457. //IRC_GroupSay(gGroupID, channel, string);
  458. //IRC_GroupSay(gGroupID, channel, "its ok (13)");
  459. //02???LCS Stunting + DM + FunRoam??? 03Gamemode: Stunt|DM|Parkour|Race|Gangs 04Map: San Andreas 06Players: 19/49 07Server Version: 0.3c R5 13Password: No. 10Time: 13:00 11Weather: 10 14Website: www.lcs-server.co.uk
  460. }
  461. //IRC_GroupSay(gGroupID, channel, "its ok (14)");
  462. else IRC_GroupSay(gGroupID, channel, "4Error: Server is offline!");
  463. //IRC_GroupSay(gGroupID, channel, "its ok (15)");
  464. return 1;
  465. }
  466.  
  467. IRCCMD:restart(botid, channel[], user[], host[], params[])
  468. {
  469. if(IsOwner)
  470. {
  471. SendRconCommand("gmx");
  472. IRC_GroupSay(gGroupID, channel, "04 Restarting the system!");
  473. }
  474. return 1;
  475. }
  476.  
  477. IRCCMD:google(botid, channel[], user[], host[], params[])
  478. {
  479. new type[50], search[800];
  480. if (unformat(params, "ss[500]", type, search)) return IRC_Notice(botid, user, "4Error: !google [type] [search]");
  481. if (strfind(type, "search", true) == -1 && strfind(type, "images", true) == -1 && strfind(type, "maps", true) == -1) return IRC_GroupSay(gGroupID, channel, "4 *** Error: Types: Search, Images, Maps");
  482. new string[256];
  483. format(string, sizeof(string), "http://www.google.com/%s?q=%s", type, replaceChar(search, ' ', '+'));
  484. IRC_GroupSay(gGroupID, channel, string);
  485. return 1;
  486. }
  487.  
  488. IRCCMD:join(botid, channel[], user[], host[], params[])
  489. {
  490. if(IsOwner)
  491. {
  492. new jchannel[50];
  493. if (sscanf(params, "s[50]", jchannel)) return IRC_Notice(botid, user, "4Error: !join [Channel]");
  494. IRC_JoinChannel(gBotID[0], jchannel);
  495. IRC_GroupSay(gGroupID, channel, "Done.");
  496. }
  497. return 1;
  498. }
  499.  
  500. IRCCMD:part(botid, channel[], user[], host[], params[])
  501. {
  502. if(IsOwner)
  503. {
  504. new string[128];
  505. format(string, sizeof(string), "PART %s\r\n", channel);
  506. IRC_SendRaw(botid, string);
  507. }
  508. return 1;
  509. }
  510.  
  511. IRCCMD:info(botid, channel[], user[], host[], params[])
  512. {
  513. new string[128];
  514.  
  515. format(string, sizeof(string), " 12* Version: %s", systemv);
  516. IRC_GroupSay(gGroupID, channel, string);
  517.  
  518. if(!mysql_ping())
  519. {
  520. IRC_GroupSay(gGroupID, channel, "10* My7SQL: Connection is alive!");
  521. }
  522. else
  523. {
  524. IRC_GroupSay(gGroupID, channel, "10* My7SQL: Connection is dead!");
  525. }
  526.  
  527. format(string, sizeof(string), "13* Auto-Join: %d auto-join channels saved.", CountAutoJoinChannels());
  528. IRC_GroupSay(gGroupID, channel, string);
  529.  
  530. format(string, sizeof(string), "11* Admins: I've %d admin(s).", CountTotalAdmins());
  531. IRC_GroupSay(gGroupID, channel, string);
  532.  
  533. /***
  534. * Uptime
  535. */
  536.  
  537. new
  538. seconds, minutes, hours, days, uptime, stri[ 256 ];
  539.  
  540. uptime = gettime() - starttime;
  541. if (uptime > 86400) {
  542. days = uptime/86400; uptime = uptime - (86400 * days); }
  543. if (uptime > 3600) {
  544. hours = uptime/3600; uptime = uptime - (3600 * hours); }
  545. if (uptime > 60) {
  546. minutes = uptime/60; uptime = uptime - (60 * minutes); }
  547. seconds = uptime;
  548. //format(string,sizeof(string),"Days:%d Hours:%d Minutes:%d Seconds:%d",days,hours,minutes,seconds);
  549. //IRC_Say(gGroupID,channel,string);
  550.  
  551. format(stri, sizeof(stri), "2* System Uptime: Days:%d Hours:%d Minutes:%d Seconds:%d",days,hours,minutes,seconds);
  552. IRC_GroupSay(gGroupID, channel, stri);
  553.  
  554. return 1;
  555. }
  556.  
  557.  
  558. IRCCMD:addjoin(botid, channel[], user[], host[], params[])
  559. {
  560. if(IsOwner)
  561. {
  562. new JoinChannel[80];
  563.  
  564. if (unformat(params, "s[80]", JoinChannel)) return IRC_Notice(botid, user, "4Error: !addjoin [channel]");
  565.  
  566. if (IsChannelAutoJoin(JoinChannel)) return IRC_Notice(botid, user, "4Error: This channel was already added.");
  567.  
  568. new sql[128], string[128];
  569.  
  570. format(sql, sizeof(sql), "INSERT INTO `autojoin` (`channel`) values ('%s')", JoinChannel);
  571. SendQuery(sql);
  572. format(string, sizeof(string), "3Success: Channel %s was successfully inserted into the auto join list.", JoinChannel);
  573.  
  574. IRC_Notice(botid, user, string);
  575. }
  576. return 1;
  577. }
  578.  
  579. IRCCMD:deletejoin(botid, channel[], user[], host[], params[])
  580. {
  581. if(IsOwner)
  582. {
  583. new JoinChannel[80];
  584.  
  585. if (unformat(params, "s[80]", JoinChannel)) return IRC_Notice(botid, user, "4Error: !deletejoin [channel]");
  586.  
  587. if (!IsChannelAutoJoin(JoinChannel)) return IRC_Notice(botid, user, "4Error: This channel is not on the auto join list.");
  588.  
  589. new sql[128], string[128];
  590.  
  591. format(sql, sizeof(sql), "DELETE FROM autojoin WHERE channel = '%s'", JoinChannel);
  592. SendQuery(sql);
  593. format(string, sizeof(string), "3Success: Channel %s was successfully removed from the auto join list.", JoinChannel);
  594.  
  595. IRC_Notice(botid, user, string);
  596. }
  597. return 1;
  598. }
  599.  
  600. IRCCMD:setadmin(botid, channel[], user[], host[], params[])
  601. {
  602. if(IsOwner)
  603. {
  604. new
  605. admin[ 80 ];
  606.  
  607. //IRC_GroupSay(gGroupID, channel, "its ok (1)");
  608.  
  609. if (unformat(params, "s[80]", admin)) return IRC_Notice(botid, user, "4Error: !setadmin [userName]");
  610.  
  611. //IRC_GroupSay(gGroupID, channel, "its ok (2)");
  612.  
  613. if (IsUserAdmin( admin )) return IRC_Notice(botid, user, "4Error: This user was already added.");
  614.  
  615. //IRC_GroupSay(gGroupID, channel, "its ok (3)");
  616.  
  617. new
  618. sql[ 128 ], string[ 128 ];
  619.  
  620. // IRC_GroupSay(gGroupID, channel, "its ok (4)");
  621.  
  622. format(sql, sizeof( sql ), "INSERT INTO `owners` (`name`) values ('%s')", admin);
  623.  
  624. //IRC_GroupSay(gGroupID, channel, "its ok (5)");
  625.  
  626. SendQuery( sql );
  627.  
  628. //IRC_GroupSay(gGroupID, channel, "its ok (6)");
  629.  
  630. format(string, sizeof( string ), "3Success: %s has been added as admin!", admin);
  631.  
  632. //IRC_GroupSay(gGroupID, channel, "its ok (7)");
  633.  
  634. IRC_Notice(botid, user, string);
  635. }
  636. return 1;
  637. }
  638.  
  639.  
  640. IRCCMD:removeadmin(botid, channel[], user[], host[], params[])
  641. {
  642. if(IsOwner)
  643. {
  644. new
  645. admin[ 80 ];
  646.  
  647. if (unformat(params, "s[80]", admin)) return IRC_Notice(botid, user, "4Error: !removeadmin [userName]");
  648.  
  649. if (!IsUserAdmin( admin )) return IRC_Notice(botid, user, "4Error: This user is not on the admin list.");
  650.  
  651. new
  652. sql[ 128 ], string[ 128 ];
  653.  
  654. format(sql, sizeof( sql ), "DELETE FROM `owners` WHERE `name` = '%s'", admin);
  655. SendQuery( sql );
  656. format(string, sizeof( string ), "3Success: User %s was successfully removed from the admin list.", admin);
  657.  
  658. IRC_Notice(botid, user, string);
  659. }
  660. return 1;
  661. }
  662.  
  663.  
  664.  
  665. IRCCMD:admins(botid, channel[], user[], host[], params[])
  666. {
  667. new
  668. data[ 50 ], string [ 128 ];
  669.  
  670. mysql_query("SELECT * FROM owners ORDER BY ID ASC");
  671.  
  672. mysql_store_result();
  673.  
  674. while( mysql_fetch_row( data ))
  675. {
  676. mysql_fetch_field("ID", data);
  677. mysql_fetch_field("name", data);
  678.  
  679. }
  680. //IRC_GroupSay(gGroupID, channel, string);
  681. format(string, sizeof( string ), "%d: %s", data, data);
  682. IRC_GroupSay(gGroupID, channel, string);
  683. return 1;
  684. }
  685.  
  686. //SELECT `name` FROM `users` ORDER BY id
  687.  
  688. IRCCMD:rejoin(botid, channel[], user[], host[], params[])
  689. {
  690. if(IsOwner)
  691. {
  692. IRC_PartChannel(botid, channel);
  693. IRC_JoinChannel(botid, channel);
  694. }
  695. return 1;
  696. }
  697.  
  698. IRCCMD:repeat(botid, channel[], user[], host[], params[])
  699. {
  700. if(IsOwner)
  701. {
  702. new amount, text[500];
  703.  
  704. if (unformat(params, "ds[500]", amount, text)) return IRC_Notice(botid, user, "4Error: !repeat [Amount] [text]");
  705.  
  706. Loop(i, amount)
  707. {
  708. IRC_GroupSay(gGroupID, channel, text);
  709. }
  710.  
  711. }
  712. return 1;
  713. }
  714.  
  715. IRCCMD:calc(botid, channel[], user[], host[], params[])
  716. {
  717. new num1, num2, sing[20];
  718.  
  719. if (unformat(params, "d[50]s[20]d[50]", num1, sing, num2)) return IRC_Notice(botid, user, "4Error: !calc [Num1] [Sing] [Num2]");
  720.  
  721. new results;
  722.  
  723. if (strfind(sing, "+", true) != -1)
  724. {
  725. results = num1 + num2;
  726. }
  727. else if (strfind(sing, "-", true) != -1)
  728. {
  729. results = num1 - num2;
  730. }
  731. else if (strfind(sing, "*", true) != -1 || strfind(sing, "x", true) != -1)
  732. {
  733. results = num1 * num2;
  734. }
  735. else if (strfind(sing, "/", true) != -1)
  736. {
  737. results = num1 / num2;
  738. }
  739. else
  740. {
  741. IRC_Notice(botid, user, "4Error: !calc [Num1] [Sing] [Num2]");
  742. }
  743.  
  744. new string[128];
  745.  
  746. format(string, sizeof(string), "3 *** Results: %d", results);
  747.  
  748. IRC_GroupSay(gGroupID, channel, string);
  749.  
  750. return 1;
  751. }
  752.  
  753. IRCCMD:dots(botid, channel[], user[], host[], params[])
  754. {
  755. if(IsOwner)
  756. {
  757. if (DotReplace == 1)
  758. {
  759. DotReplace = 0;
  760. IRC_GroupSay(gGroupID, channel, "4 *** Dots Replacement: Off.");
  761. }
  762. else
  763. {
  764. DotReplace = 1;
  765. IRC_GroupSay(gGroupID, channel, "3 *** Dots Replacement: On.");
  766. }
  767. }
  768. return 1;
  769. }
  770.  
  771. IRCCMD:copyme(botid, channel[], user[], host[], params[])
  772. {
  773. if(IsOwner)
  774. {
  775. if (CopyMe == 1)
  776. {
  777. CopyMe = 0;
  778. IRC_GroupSay(gGroupID, channel, "4 *** CopyMe: Off.");
  779. }
  780. else
  781. {
  782. CopyMe = 1;
  783. IRC_GroupSay(gGroupID, channel, "3 *** CopyMe: On.");
  784. }
  785. }
  786. return 1;
  787. }
  788.  
  789. replaceChar(string[800], findchar, replacechar)
  790. {
  791. for(new i; string[i]; ++i)
  792. {
  793. if(string[i] == findchar) string[i] = replacechar;
  794. }
  795. return string;
  796. }
  797.  
  798. //======
  799. // Stocks
  800. //======
  801.  
  802. stock CountAutoJoinChannels()
  803. {
  804. mysql_query("SELECT * FROM `autojoin`");
  805.  
  806. mysql_store_result();
  807.  
  808. new test;
  809.  
  810. test = mysql_num_rows();
  811.  
  812. mysql_free_result();
  813.  
  814. return test;
  815. }
  816.  
  817. stock CountTotalAdmins()
  818. {
  819. mysql_query("SELECT `ID` FROM `owners`");
  820.  
  821. mysql_store_result();
  822.  
  823. new test;
  824.  
  825. test = mysql_num_rows();
  826.  
  827. mysql_free_result();
  828.  
  829. return test;
  830. }
  831.  
  832. stock AdminList()
  833. {
  834. new result[ 124 ];
  835.  
  836. mysql_query("SELECT `name` FROM `owners` ORDER BY id ASC");
  837.  
  838. mysql_store_result();
  839.  
  840. new test;
  841.  
  842. test = mysql_fetch_row(result);
  843.  
  844. mysql_free_result();
  845.  
  846. return test;
  847. }
  848.  
  849. stock IsOwner2(botid, channel[], user[])
  850. {
  851. new IsOwnerS;
  852.  
  853. printf("Botid: %d User: %s Channel: %s",botid, user, channel);
  854.  
  855. if (strfind(user, "shabeer", true) != -1)
  856. {
  857. if (IRC_IsHalfop(botid, channel, user))
  858. {
  859. IsOwnerS = true;
  860. }
  861. else if (IRC_IsOp(botid, channel, user))
  862. {
  863. IsOwnerS = true;
  864. }
  865. else if (IRC_IsAdmin(botid, channel, user))
  866. {
  867. IsOwnerS = true;
  868. }
  869. else if (IRC_IsOwner(botid, channel, user))
  870. {
  871. IsOwnerS = true;
  872. }
  873. else
  874. {
  875. IsOwnerS = false;
  876. }
  877. }
  878. else
  879. {
  880. IsOwnerS = false;
  881. }
  882.  
  883. return IsOwnerS;
  884. }
  885.  
  886. stock IsNumeric(string[])
  887. {
  888. for (new i = 0, j = strlen(string); i < j; i++)
  889. {
  890. if (string[i] > '9' || string[i] < '0') return 0;
  891. }
  892. return 1;
  893. }
  894.  
  895. stock IsPlayerRegistered(playername[])
  896. {
  897. new sql[512];
  898.  
  899. format(sql, sizeof(sql), "SELECT * FROM `users` WHERE `username` = '%s'", playername);
  900. SendQuery(sql);
  901.  
  902. mysql_store_result();
  903.  
  904. if (mysql_num_rows() == 0)
  905. {
  906. return false;
  907. }
  908.  
  909. return true;
  910. }
  911.  
  912. stock IsChannelAutoJoin(channel[])
  913. {
  914. new sql[512];
  915.  
  916. format(sql, sizeof(sql), "SELECT * FROM `autojoin` WHERE `channel` = '%s'", channel);
  917. SendQuery(sql);
  918.  
  919. mysql_store_result();
  920.  
  921. if (mysql_num_rows() == 0)
  922. {
  923. return false;
  924. }
  925.  
  926. return true;
  927. }
  928.  
  929. stock IsUserAdmin(userName[])
  930. {
  931. new sql[512];
  932.  
  933. format(sql, sizeof(sql), "SELECT * FROM `owners` WHERE `name` = '%s'", userName);
  934. SendQuery(sql);
  935.  
  936. mysql_store_result();
  937.  
  938. if (mysql_num_rows() == 0)
  939. {
  940. return false;
  941. }
  942.  
  943. return true;
  944. }
  945.  
  946.  
  947. /*stock IsUserOwner(owner[])
  948. {
  949. new sql[512];
  950.  
  951. format(sql, sizeof(sql), "SELECT * FROM `owners` WHERE `name` = '%s'", owner);
  952. SendQuery(sql);
  953.  
  954. mysql_store_result();
  955.  
  956. if (mysql_num_rows() == 0)
  957. {
  958. return false;
  959. }
  960.  
  961. return true;
  962. }*/
  963.  
  964. stock strtok(const string[], &index)
  965. {
  966. new length = strlen(string);
  967. while ((index < length) && (string[index] <= ' '))
  968. {
  969. index++;
  970. }
  971.  
  972. new offset = index;
  973. new result[20];
  974. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  975. {
  976. result[index - offset] = string[index];
  977. index++;
  978. }
  979. result[index - offset] = EOS;
  980. return result;
  981. }
  982.  
  983. stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
  984. {
  985. new
  986. iLengthTarget = strlen(sSearch),
  987. iLengthReplace = strlen(sReplace),
  988. iLengthSource = strlen(sSubject),
  989. iItterations = (iLengthSource - iLengthTarget) + 1;
  990.  
  991. new sTemp[128], sReturn[128];
  992.  
  993. strcat(sReturn, sSubject, 128);
  994. iCount = 0;
  995.  
  996. for(new iIndex; iIndex < iItterations; ++iIndex)
  997. {
  998. strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));
  999.  
  1000. if(!strcmp(sTemp, sSearch, false))
  1001. {
  1002. strdel(sReturn, iIndex, (iIndex + iLengthTarget));
  1003. strins(sReturn, sReplace, iIndex, iLengthReplace);
  1004.  
  1005. iIndex += iLengthTarget;
  1006. iCount++;
  1007. }
  1008. }
  1009.  
  1010. return sReturn;
  1011. }
  1012.  
Advertisement
Add Comment
Please, Sign In to add comment