Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------- IRC bot using MySQL! BY Anurag-----------------------------------------------------//
- //---------------------------------------------- DO NOT REMOVE THE CREDITS-----------------------------------------------------------//
- //------------------------------------------------------ Thanks :D-------------------------------------------------------------------//
- #include <a_samp>#include <a_samp>
- #include <mysql>
- #include <irc>
- #include <sscanf2>
- #include <ServerQuery>
- #include <a_http>
- #define CMD(%1) IRCCMD:%1(botid,channel[],user[],host[],params[])//these dont need "" marks
- #define AI(%1) if(!strcmp(message,%1,true))// these need to be in "" marks
- #define IsOwner !strcmp(host,"ident@host")
- #define BOT_1_NICKNAME "" // Name that everyone will see
- #define BOT_1_REALNAME "" // Name that will only be visible in a whois
- #define BOT_1_USERNAME "" // Name that will be in front of the hostname (username@hostname)
- #define IRC_SERVER "irc.tl"
- #define IRC_PORT (6667)
- #define IRC_CHANNEL ""
- #define IRC_BOT_PASSWORD "" // Put a password here.
- // Maximum number of bots in the filterscript
- #define MAX_BOTS (100)
- //Mysql
- #define MYSQL_HOST "localhost"
- #define MYSQL_USER "root"
- #define MYSQL_PASS ""
- #define MYSQL_DB ""
- #define systemv "2.5.6"
- #define Loop(%0,%1) \
- for(new %0; %0 != %1; %0++)
- new starttime;
- new
- gBotID[MAX_BOTS],
- gGroupID;
- new CopyMe = 0;
- new DotReplace = 0;
- //new Registering = 0;
- //new UserToRegister;
- main()
- {
- print("+==========================================+");
- print("| |");
- print("| Starting Shabby By ANURAG |");
- print("| |");
- print("+==========================================+");
- }
- public OnGameModeInit()
- {
- mysql_start();//Connect to Mysql
- SetTimerEx("IRC_ConnectDelay", 100, 0, "d", 1);// Wait 2 seconds for the first bot
- SetTimer("Sendrand", 70000, true);
- SetTimer("LCSUpdate",600000,1);
- gGroupID = IRC_CreateGroup();// Create a group (the bots will be added to it upon connect)
- return 1;
- }
- public OnGameModeExit()
- {
- mysql_close();//close Mysql
- IRC_Quit(gBotID[0], "Good Bye!"); // Disconnect the first bot
- IRC_DestroyGroup(gGroupID);// Destroy the group
- return 1;
- }
- forward RestartGM();
- public RestartGM()
- {
- SendRconCommand("gmx");
- }
- // Using this you can make your bot talk randomly.
- /*new SAYRAND[][] =
- {
- "msg 1",
- "msg 2",
- "msg 3"
- "so on....."
- };
- forward Sendrand();
- public Sendrand()
- {
- new randMSG = random(sizeof(SAYRAND));
- IRC_Say(gBotID[0], "#channel", SAYRAND[randMSG]);
- }*/
- //Mysql
- forward AutoJoinChannels(botid);
- public AutoJoinChannels(botid)
- {
- new
- string[ 128 ], data[ 256 ];
- mysql_query("SELECT * FROM `autojoin`");
- mysql_store_result();
- if (mysql_num_rows() > 0)
- {
- new count = 0;
- while(mysql_fetch_row(data))
- {
- mysql_fetch_field("channel",data);
- IRC_JoinChannel(botid, data);
- printf("Channel: %s", data);
- count++;
- }
- format(string, sizeof( string ), " 12* Version: %s", systemv);
- IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
- if(!mysql_ping())
- {
- IRC_GroupSay(gGroupID, IRC_CHANNEL, "10* My7SQL: Connection is alive!");
- }
- else
- {
- IRC_GroupSay(gGroupID, IRC_CHANNEL, "10* My7SQL: Connection is dead!");
- }
- format(string, sizeof( string ), "13* Auto-Join: %d auto-join channels saved.", count);
- IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
- format(string, sizeof( string ), "11* Admins: I've %d admin(s).", CountTotalAdmins());
- IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
- format(string, sizeof( string ), "14* Plugins: Currently 4 plugins are loaded.");
- IRC_GroupSay(gGroupID, IRC_CHANNEL, string);
- }
- mysql_free_result();
- }
- forward mysql_start();
- public mysql_start()
- {
- new MySQL:connection = mysql_init(LOG_ONLY_ERRORS, 1);
- if (mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, connection))
- {
- print("+================================+");
- print("| |");
- print("| [MYSQL] Connection successful! |");
- print("| |");
- print("+================================+");
- }
- else
- {
- print("[MYSQL] There was an error connecting to the MYSQL server. Shit!");
- }
- return 1;
- }
- forward CheckSQL();
- public CheckSQL()
- {
- new bool:connected;
- if (mysql_ping() != 0)
- {
- connected = false;
- }
- else
- {
- connected = true;
- }
- if (connected == false)
- {
- print("[MYSQL] Lost connection to MYSQL server, Reconnecting...");
- mysql_start();
- }
- return 1;
- }
- forward SendQuery(query[]);
- public SendQuery(query[])
- {
- CheckSQL();
- if (mysql_query(query))
- {
- //printf("[MYSQL] MySQL query successful. (%s)", query);
- //printf("[MYSQL] MySQL query successful.");
- }
- else
- {
- //printf("[MYSQL] MySQL query unsuccessful. (%s)", query);
- //printf("[MYSQL] MySQL query unsuccessful.");
- return false;
- }
- return 1;
- }
- //IRC Publics
- public IRC_OnConnect(botid)
- {
- IRC_AddToGroup(gGroupID, botid);
- printf("*** IRC_OnConnect: Bot ID %d connected!", botid);
- AutoJoinChannels(botid);
- starttime = gettime();
- return 1;
- }
- public IRC_OnDisconnect(botid)
- {
- printf("*** IRC_OnDisconnect: Bot ID %d disconnected!", botid);
- if (botid == gBotID[0])
- {
- gBotID[0] = 0;
- SetTimerEx("IRC_ConnectDelay", 10000, 0, "d", 1);
- }
- printf("*** IRC_OnDisconnect: Bot ID %d attempting to reconnect...", botid);
- // Remove the bot from the group
- IRC_RemoveFromGroup(gGroupID, botid);
- return 1;
- }
- forward IRC_ConnectDelay(tempid);
- public IRC_ConnectDelay(tempid)
- {
- switch (tempid)
- {
- case 1:
- {
- // Connect the first bot
- gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
- }
- /*
- case 2:
- {
- // Connect the second bot
- gBotID[1] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_2_NICKNAME, BOT_2_REALNAME, BOT_2_USERNAME);
- }
- */
- }
- return 1;
- }
- /*
- This callback is executed whenever a connection attempt begins. IRC_Quit may
- be called at any time to stop the reconnection process.
- */
- public IRC_OnConnectAttempt(botid, ip[], port)
- {
- printf("*** IRC_OnConnectAttempt: Bot ID %d attempting to connect to %s:%d...", botid, ip, port);
- return 1;
- }
- /*
- This callback is executed whenever a connection attempt fails. IRC_Quit may
- be called at any time to stop the reconnection process.
- */
- public IRC_OnConnectAttemptFail(botid, ip[], port, reason[])
- {
- printf("*** IRC_OnConnectAttemptFail: Bot ID %d failed to connect to %s:%d (%s)", botid, ip, port, reason);
- return 1;
- }
- /*
- This callback is executed whenever a bot joins a channel.
- */
- public IRC_OnJoinChannel(botid, channel[])
- {
- printf("*** IRC_OnJoinChannel: Bot ID %d joined channel %s", botid, channel);
- return 1;
- }
- /*
- This callback is executed whenevever a bot leaves a channel.
- */
- public IRC_OnLeaveChannel(botid, channel[], message[])
- {
- printf("*** IRC_OnLeaveChannel: Bot ID %d left channel %s (%s)", botid, channel, message);
- IRC_JoinChannel(botid, channel);
- return 1;
- }
- /*
- This callback is executed whenevever a bot is kicked from a channel. If the
- bot cannot immediately rejoin the channel (in the event, for example, that
- the bot is kicked and then banned), you might want to set up a timer here
- for rejoin attempts.
- */
- public IRC_OnKickedFromChannel(botid, channel[], oppeduser[], oppedhost[], message[])
- {
- printf("*** IRC_OnKickedFromChannel: Bot ID %d kicked by %s (%s) from channel %s (%s)", botid, oppeduser, oppedhost, channel, message);
- IRC_JoinChannel(botid, channel);
- return 1;
- }
- public IRC_OnUserDisconnect(botid, user[], host[], message[])
- {
- printf("*** IRC_OnUserDisconnect (Bot ID %d): User %s (%s) disconnected (%s)", botid, user, host, message);
- return 1;
- }
- public IRC_OnUserJoinChannel(botid, channel[], user[], host[])
- {
- printf("*** IRC_OnUserJoinChannel (Bot ID %d): User %s (%s) joined channel %s", botid, user, host, channel);
- return 1;
- }
- public IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[])
- {
- printf("*** IRC_OnUserLeaveChannel (Bot ID %d): User %s (%s) left channel %s (%s)", botid, user, host, channel, message);
- return 1;
- }
- public IRC_OnUserKickedFromChannel(botid, channel[], kickeduser[], oppeduser[], oppedhost[], message[])
- {
- printf("*** IRC_OnUserKickedFromChannel (Bot ID %d): User %s kicked by %s (%s) from channel %s (%s)", botid, kickeduser, oppeduser, oppedhost, channel, message);
- }
- public IRC_OnUserNickChange(botid, oldnick[], newnick[], host[])
- {
- printf("*** IRC_OnUserNickChange (Bot ID %d): User %s (%s) changed his/her nick to %s", botid, oldnick, host, newnick);
- return 1;
- }
- public IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[])
- {
- printf("*** IRC_OnUserSetChannelMode (Bot ID %d): User %s (%s) on %s set mode: %s", botid, user, host, channel, mode);
- return 1;
- }
- public IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[])
- {
- printf("*** IRC_OnUserSetChannelTopic (Bot ID %d): User %s (%s) on %s set topic: %s", botid, user, host, channel, topic);
- return 1;
- }
- public IRC_OnUserNotice(botid, recipient[], user[], host[], message[])
- {
- printf("*** IRC_OnUserNotice (Bot ID %d): User %s (%s) sent notice to %s: %s", botid, user, host, recipient, message);
- // Someone sent the second bot a notice (probably a network service)
- if (!strcmp(recipient, BOT_1_NICKNAME))
- {
- IRC_Notice(botid, user, "Why did you send me a notice?");
- }
- return 1;
- }
- public IRC_OnUserRequestCTCP(botid, user[], host[], message[])
- {
- printf("*** IRC_OnUserRequestCTCP (Bot ID %d): User %s (%s) sent CTCP request: %s", botid, user, host, message);
- // Someone sent a CTCP VERSION request
- if (!strcmp(message, "VERSION"))
- {
- IRC_ReplyCTCP(botid, user, "version Shabby 1.0 - Shabeer; http://shabeer.us");
- }
- return 1;
- }
- public IRC_OnUserReplyCTCP(botid, user[], host[], message[])
- {
- printf("*** IRC_OnUserReplyCTCP (Bot ID %d): User %s (%s) sent CTCP reply: %s", botid, user, host, message);
- return 1;
- }
- /*
- This callback is useful for logging, debugging, or catching error messages
- sent by the IRC server.
- */
- public IRC_OnReceiveRaw(botid, message[])
- {
- new File:file;
- if (!fexist("irc_log.txt"))
- {
- file = fopen("irc_log.txt", io_write);
- }
- else
- {
- file = fopen("irc_log.txt", io_append);
- }
- if (file)
- {
- fwrite(file, message);
- fwrite(file, "\r\n");
- fclose(file);
- }
- return 1;
- }
- public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
- {
- printf("*** IRC_OnUserSay (Bot ID %d): User %s (%s) sent message to %s: %s", botid, user, host, recipient, message);
- // Someone sent the first bot a private message
- if (DotReplace == 1)
- {
- new string[500];
- format(string, sizeof(string), "%s", str_replace(".", "DOT", message));
- IRC_GroupSay(gGroupID, recipient, string);
- }
- if (CopyMe == 1)
- {
- IRC_GroupSay(gGroupID, recipient, message);
- }
- return 1;
- }
- IRCCMD:serverinfo(botid, channel[], user[], host[], params[])
- {
- //IRC_GroupSay(gGroupID, channel, "its ok (1)");
- new ip[32], port;
- //IRC_GroupSay(gGroupID, channel, "its ok (2)");
- if(sscanf(params, "p<:>s[32]i", ip, port)) return IRC_GroupSay(gGroupID, channel, "4Error: !serverinfo <ip> <port>");
- //IRC_GroupSay(gGroupID, channel, "its ok (3)");
- if(GetInfoPacket(ip, port))
- {
- //IRC_GroupSay(gGroupID, channel, "its ok (4)");
- new string[256], hostname[75], gamemode[45], mapname[35],SQplayers;
- //IRC_GroupSay(gGroupID, channel, "its ok (5)");
- iGetHostname(hostname);
- //IRC_GroupSay(gGroupID, channel, "its ok (6)");
- iGetGamemode(gamemode);
- //IRC_GroupSay(gGroupID, channel, "its ok (7)");
- iGetMapname(mapname);
- //IRC_GroupSay(gGroupID, channel, "its ok (8)");
- SQplayers = iGetPlayers();
- //IRC_GroupSay(gGroupID, channel, "its ok (9)");
- format(string,sizeof string,"02 %s 03Gamemode: %s 04Map: %s 06Players: %d/%d 13Passworded: %d",hostname,gamemode,mapname,SQplayers,iGetMaxPlayers(),iIsPassworded());
- //IRC_GroupSay(gGroupID, channel, "its ok (10)");
- IRC_GroupSay(gGroupID, channel, string);
- //IRC_GroupSay(gGroupID, channel, "its ok (11)");
- //format(string,sizeof string,"%d Players, GM: %s, Mapname: %s",SQplayers,gamemode,mapname);
- //IRC_GroupSay(gGroupID, channel, "its ok (12)");
- //IRC_GroupSay(gGroupID, channel, string);
- //IRC_GroupSay(gGroupID, channel, "its ok (13)");
- //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
- }
- //IRC_GroupSay(gGroupID, channel, "its ok (14)");
- else IRC_GroupSay(gGroupID, channel, "4Error: Server is offline!");
- //IRC_GroupSay(gGroupID, channel, "its ok (15)");
- return 1;
- }
- IRCCMD:restart(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- SendRconCommand("gmx");
- IRC_GroupSay(gGroupID, channel, "04 Restarting the system!");
- }
- return 1;
- }
- IRCCMD:google(botid, channel[], user[], host[], params[])
- {
- new type[50], search[800];
- if (unformat(params, "ss[500]", type, search)) return IRC_Notice(botid, user, "4Error: !google [type] [search]");
- 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");
- new string[256];
- format(string, sizeof(string), "http://www.google.com/%s?q=%s", type, replaceChar(search, ' ', '+'));
- IRC_GroupSay(gGroupID, channel, string);
- return 1;
- }
- IRCCMD:join(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new jchannel[50];
- if (sscanf(params, "s[50]", jchannel)) return IRC_Notice(botid, user, "4Error: !join [Channel]");
- IRC_JoinChannel(gBotID[0], jchannel);
- IRC_GroupSay(gGroupID, channel, "Done.");
- }
- return 1;
- }
- IRCCMD:part(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new string[128];
- format(string, sizeof(string), "PART %s\r\n", channel);
- IRC_SendRaw(botid, string);
- }
- return 1;
- }
- IRCCMD:info(botid, channel[], user[], host[], params[])
- {
- new string[128];
- format(string, sizeof(string), " 12* Version: %s", systemv);
- IRC_GroupSay(gGroupID, channel, string);
- if(!mysql_ping())
- {
- IRC_GroupSay(gGroupID, channel, "10* My7SQL: Connection is alive!");
- }
- else
- {
- IRC_GroupSay(gGroupID, channel, "10* My7SQL: Connection is dead!");
- }
- format(string, sizeof(string), "13* Auto-Join: %d auto-join channels saved.", CountAutoJoinChannels());
- IRC_GroupSay(gGroupID, channel, string);
- format(string, sizeof(string), "11* Admins: I've %d admin(s).", CountTotalAdmins());
- IRC_GroupSay(gGroupID, channel, string);
- /***
- * Uptime
- */
- new
- seconds, minutes, hours, days, uptime, stri[ 256 ];
- uptime = gettime() - starttime;
- if (uptime > 86400) {
- days = uptime/86400; uptime = uptime - (86400 * days); }
- if (uptime > 3600) {
- hours = uptime/3600; uptime = uptime - (3600 * hours); }
- if (uptime > 60) {
- minutes = uptime/60; uptime = uptime - (60 * minutes); }
- seconds = uptime;
- //format(string,sizeof(string),"Days:%d Hours:%d Minutes:%d Seconds:%d",days,hours,minutes,seconds);
- //IRC_Say(gGroupID,channel,string);
- format(stri, sizeof(stri), "2* System Uptime: Days:%d Hours:%d Minutes:%d Seconds:%d",days,hours,minutes,seconds);
- IRC_GroupSay(gGroupID, channel, stri);
- return 1;
- }
- IRCCMD:addjoin(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new JoinChannel[80];
- if (unformat(params, "s[80]", JoinChannel)) return IRC_Notice(botid, user, "4Error: !addjoin [channel]");
- if (IsChannelAutoJoin(JoinChannel)) return IRC_Notice(botid, user, "4Error: This channel was already added.");
- new sql[128], string[128];
- format(sql, sizeof(sql), "INSERT INTO `autojoin` (`channel`) values ('%s')", JoinChannel);
- SendQuery(sql);
- format(string, sizeof(string), "3Success: Channel %s was successfully inserted into the auto join list.", JoinChannel);
- IRC_Notice(botid, user, string);
- }
- return 1;
- }
- IRCCMD:deletejoin(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new JoinChannel[80];
- if (unformat(params, "s[80]", JoinChannel)) return IRC_Notice(botid, user, "4Error: !deletejoin [channel]");
- if (!IsChannelAutoJoin(JoinChannel)) return IRC_Notice(botid, user, "4Error: This channel is not on the auto join list.");
- new sql[128], string[128];
- format(sql, sizeof(sql), "DELETE FROM autojoin WHERE channel = '%s'", JoinChannel);
- SendQuery(sql);
- format(string, sizeof(string), "3Success: Channel %s was successfully removed from the auto join list.", JoinChannel);
- IRC_Notice(botid, user, string);
- }
- return 1;
- }
- IRCCMD:setadmin(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new
- admin[ 80 ];
- //IRC_GroupSay(gGroupID, channel, "its ok (1)");
- if (unformat(params, "s[80]", admin)) return IRC_Notice(botid, user, "4Error: !setadmin [userName]");
- //IRC_GroupSay(gGroupID, channel, "its ok (2)");
- if (IsUserAdmin( admin )) return IRC_Notice(botid, user, "4Error: This user was already added.");
- //IRC_GroupSay(gGroupID, channel, "its ok (3)");
- new
- sql[ 128 ], string[ 128 ];
- // IRC_GroupSay(gGroupID, channel, "its ok (4)");
- format(sql, sizeof( sql ), "INSERT INTO `owners` (`name`) values ('%s')", admin);
- //IRC_GroupSay(gGroupID, channel, "its ok (5)");
- SendQuery( sql );
- //IRC_GroupSay(gGroupID, channel, "its ok (6)");
- format(string, sizeof( string ), "3Success: %s has been added as admin!", admin);
- //IRC_GroupSay(gGroupID, channel, "its ok (7)");
- IRC_Notice(botid, user, string);
- }
- return 1;
- }
- IRCCMD:removeadmin(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new
- admin[ 80 ];
- if (unformat(params, "s[80]", admin)) return IRC_Notice(botid, user, "4Error: !removeadmin [userName]");
- if (!IsUserAdmin( admin )) return IRC_Notice(botid, user, "4Error: This user is not on the admin list.");
- new
- sql[ 128 ], string[ 128 ];
- format(sql, sizeof( sql ), "DELETE FROM `owners` WHERE `name` = '%s'", admin);
- SendQuery( sql );
- format(string, sizeof( string ), "3Success: User %s was successfully removed from the admin list.", admin);
- IRC_Notice(botid, user, string);
- }
- return 1;
- }
- IRCCMD:admins(botid, channel[], user[], host[], params[])
- {
- new
- data[ 50 ], string [ 128 ];
- mysql_query("SELECT * FROM owners ORDER BY ID ASC");
- mysql_store_result();
- while( mysql_fetch_row( data ))
- {
- mysql_fetch_field("ID", data);
- mysql_fetch_field("name", data);
- }
- //IRC_GroupSay(gGroupID, channel, string);
- format(string, sizeof( string ), "%d: %s", data, data);
- IRC_GroupSay(gGroupID, channel, string);
- return 1;
- }
- //SELECT `name` FROM `users` ORDER BY id
- IRCCMD:rejoin(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- IRC_PartChannel(botid, channel);
- IRC_JoinChannel(botid, channel);
- }
- return 1;
- }
- IRCCMD:repeat(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- new amount, text[500];
- if (unformat(params, "ds[500]", amount, text)) return IRC_Notice(botid, user, "4Error: !repeat [Amount] [text]");
- Loop(i, amount)
- {
- IRC_GroupSay(gGroupID, channel, text);
- }
- }
- return 1;
- }
- IRCCMD:calc(botid, channel[], user[], host[], params[])
- {
- new num1, num2, sing[20];
- if (unformat(params, "d[50]s[20]d[50]", num1, sing, num2)) return IRC_Notice(botid, user, "4Error: !calc [Num1] [Sing] [Num2]");
- new results;
- if (strfind(sing, "+", true) != -1)
- {
- results = num1 + num2;
- }
- else if (strfind(sing, "-", true) != -1)
- {
- results = num1 - num2;
- }
- else if (strfind(sing, "*", true) != -1 || strfind(sing, "x", true) != -1)
- {
- results = num1 * num2;
- }
- else if (strfind(sing, "/", true) != -1)
- {
- results = num1 / num2;
- }
- else
- {
- IRC_Notice(botid, user, "4Error: !calc [Num1] [Sing] [Num2]");
- }
- new string[128];
- format(string, sizeof(string), "3 *** Results: %d", results);
- IRC_GroupSay(gGroupID, channel, string);
- return 1;
- }
- IRCCMD:dots(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- if (DotReplace == 1)
- {
- DotReplace = 0;
- IRC_GroupSay(gGroupID, channel, "4 *** Dots Replacement: Off.");
- }
- else
- {
- DotReplace = 1;
- IRC_GroupSay(gGroupID, channel, "3 *** Dots Replacement: On.");
- }
- }
- return 1;
- }
- IRCCMD:copyme(botid, channel[], user[], host[], params[])
- {
- if(IsOwner)
- {
- if (CopyMe == 1)
- {
- CopyMe = 0;
- IRC_GroupSay(gGroupID, channel, "4 *** CopyMe: Off.");
- }
- else
- {
- CopyMe = 1;
- IRC_GroupSay(gGroupID, channel, "3 *** CopyMe: On.");
- }
- }
- return 1;
- }
- replaceChar(string[800], findchar, replacechar)
- {
- for(new i; string[i]; ++i)
- {
- if(string[i] == findchar) string[i] = replacechar;
- }
- return string;
- }
- //======
- // Stocks
- //======
- stock CountAutoJoinChannels()
- {
- mysql_query("SELECT * FROM `autojoin`");
- mysql_store_result();
- new test;
- test = mysql_num_rows();
- mysql_free_result();
- return test;
- }
- stock CountTotalAdmins()
- {
- mysql_query("SELECT `ID` FROM `owners`");
- mysql_store_result();
- new test;
- test = mysql_num_rows();
- mysql_free_result();
- return test;
- }
- stock AdminList()
- {
- new result[ 124 ];
- mysql_query("SELECT `name` FROM `owners` ORDER BY id ASC");
- mysql_store_result();
- new test;
- test = mysql_fetch_row(result);
- mysql_free_result();
- return test;
- }
- stock IsOwner2(botid, channel[], user[])
- {
- new IsOwnerS;
- printf("Botid: %d User: %s Channel: %s",botid, user, channel);
- if (strfind(user, "shabeer", true) != -1)
- {
- if (IRC_IsHalfop(botid, channel, user))
- {
- IsOwnerS = true;
- }
- else if (IRC_IsOp(botid, channel, user))
- {
- IsOwnerS = true;
- }
- else if (IRC_IsAdmin(botid, channel, user))
- {
- IsOwnerS = true;
- }
- else if (IRC_IsOwner(botid, channel, user))
- {
- IsOwnerS = true;
- }
- else
- {
- IsOwnerS = false;
- }
- }
- else
- {
- IsOwnerS = false;
- }
- return IsOwnerS;
- }
- stock IsNumeric(string[])
- {
- for (new i = 0, j = strlen(string); i < j; i++)
- {
- if (string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
- stock IsPlayerRegistered(playername[])
- {
- new sql[512];
- format(sql, sizeof(sql), "SELECT * FROM `users` WHERE `username` = '%s'", playername);
- SendQuery(sql);
- mysql_store_result();
- if (mysql_num_rows() == 0)
- {
- return false;
- }
- return true;
- }
- stock IsChannelAutoJoin(channel[])
- {
- new sql[512];
- format(sql, sizeof(sql), "SELECT * FROM `autojoin` WHERE `channel` = '%s'", channel);
- SendQuery(sql);
- mysql_store_result();
- if (mysql_num_rows() == 0)
- {
- return false;
- }
- return true;
- }
- stock IsUserAdmin(userName[])
- {
- new sql[512];
- format(sql, sizeof(sql), "SELECT * FROM `owners` WHERE `name` = '%s'", userName);
- SendQuery(sql);
- mysql_store_result();
- if (mysql_num_rows() == 0)
- {
- return false;
- }
- return true;
- }
- /*stock IsUserOwner(owner[])
- {
- new sql[512];
- format(sql, sizeof(sql), "SELECT * FROM `owners` WHERE `name` = '%s'", owner);
- SendQuery(sql);
- mysql_store_result();
- if (mysql_num_rows() == 0)
- {
- return false;
- }
- return true;
- }*/
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
- {
- new
- iLengthTarget = strlen(sSearch),
- iLengthReplace = strlen(sReplace),
- iLengthSource = strlen(sSubject),
- iItterations = (iLengthSource - iLengthTarget) + 1;
- new sTemp[128], sReturn[128];
- strcat(sReturn, sSubject, 128);
- iCount = 0;
- for(new iIndex; iIndex < iItterations; ++iIndex)
- {
- strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));
- if(!strcmp(sTemp, sSearch, false))
- {
- strdel(sReturn, iIndex, (iIndex + iLengthTarget));
- strins(sReturn, sReplace, iIndex, iLengthReplace);
- iIndex += iLengthTarget;
- iCount++;
- }
- }
- return sReturn;
- }
- //---------------------------------------------- IRC bot using MySQL! BY Anurag----------------------------------------------------//
- //---------------------------------------------- DO NOT REMOVE THE CREDITS-----------------------------------------------------------//
- //------------------------------------------------------ Thanks :D-------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement