Advertisement
Guest User

Untitled

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