Advertisement
Guest User

IRC

a guest
Jun 24th, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. /*
  2. Killers Online By hotdogcat
  3. */
  4.  
  5. const ICOL_WHITE = "0";
  6. const ICOL_BLACK = "1";
  7. const ICOL_BLUE = "2";
  8. const ICOL_GREEN = "3";
  9. const ICOL_RED = "4";
  10. const ICOL_BROWN = "5";
  11. const ICOL_PURPLE = "6";
  12. const ICOL_ORANGE = "7";
  13. const ICOL_YELLOW = "8";
  14. const ICOL_LGREEN = "9";
  15. const ICOL_CYAN = "10";
  16. const ICOL_LCYAN = "11";
  17. const ICOL_LBLUE = "12";
  18. const ICOL_PINK = "13";
  19. const ICOL_GREY = "14";
  20. const ICOL_LGREY = "15";
  21.  
  22. print( "Echo Loaded" );
  23.  
  24. /*
  25. Squirrel IRC Bot - Version 1
  26. */
  27.  
  28. const FBS_NICK = "LA";
  29. const FBS_BPASS = "";
  30. const FBS_SERVER = "91.121.134.5";
  31. const FBS_PORT = 6667;
  32. const FBS_CHAN = "#LA";
  33. const FBS_CPASS = "t"; // The password for that channel, if there isnt one leave it as "".
  34.  
  35. class FBSLIST
  36. {
  37. // This is how we are going to store the user level information for each nick currently on the channel
  38. Name = null;
  39. Level = 1;
  40. }
  41.  
  42. function FBSLIST::AddNick( szNick, iAdmin )
  43. {
  44. Name = szNick;
  45. Level = iAdmin;
  46. }
  47.  
  48. function ActivateEcho()
  49. {
  50. print( "Confirming echo bot details..." );
  51. FBS_BOT <- NewSocket( "FBSProcess" );
  52.  
  53. FBS_BOT.Connect( FBS_SERVER, FBS_PORT );
  54. FBS_BOT.SetNewConnFunc( "FBSLogin" );
  55. print( "Bot details confirmed!" );
  56.  
  57. FBS_NICKS <- array( 50, null );
  58. }
  59.  
  60. function DisconnectBots()
  61. {
  62. print( "Disconnecting bot from IRC..." );
  63.  
  64. FBS_BOT.Send( "QUIT " + FBS_NICK + "\n" );
  65. FBS_BOT.Delete();
  66.  
  67. print( FBS_NICK + " has succesfully disconnected from IRC." );
  68. }
  69.  
  70. function FBSLogin()
  71. {
  72. print( "Attempting to set user, nick and mode...." );
  73. // Set the bots name and real name
  74. FBS_BOT.Send( "USER " + FBS_NICK + " 0 * :[RD]Latino America\n" );
  75. // Set the nick that the bot will use on the irc server
  76. FBS_BOT.Send( "NICK " + FBS_NICK + "\n" );
  77. // Set it so that the network classes the bot as a bot
  78. FBS_BOT.Send( "MODE " + FBS_NICK + " +B\n" );
  79. print( "Task completed successfully." );
  80. }
  81.  
  82. function FBSProcess( sz )
  83. {
  84. // This function is used to process the raw data that the bot is recieving from the irc server
  85. local raw = split( sz, "\r\n" ), a, z = raw.len(), line;
  86.  
  87. for ( a = 0; a < z; a++ )
  88. {
  89. line = raw[ a ];
  90.  
  91. local FBS_PING = GetTok( line, " ", 1 ), FBS_EVENT = GetTok( line, " ", 2 ), FBS_CHANEVENT = GetTok( line, " ", 3 ),
  92. Count = NumTok( line, " " ), Nick, Command, Prefix, Text;
  93.  
  94. // The most important thing is making sure that the bot stays connected to IRC
  95. if ( FBS_PING ) FBS_BOT.Send( "PONG " + FBS_PING + "\n" );
  96.  
  97. if ( FBS_EVENT == "001" )
  98. {
  99. if ( FBS_BOT )
  100. {
  101. // Identify the bot with services, comment this line if its not registered
  102. FBS_BOT.Send( "PRIVMSG NickServ IDENTIFY " + FBS_BPASS + "\n" );
  103. // Set it so that the network classes the bot as a bot
  104. FBS_BOT.Send( "MODE " + FBS_NICK + " +B\n" );
  105. // Make the bot join the specified channel
  106. FBS_BOT.Send( "JOIN " + FBS_CHAN + " " + FBS_CPASS + "\n" );
  107.  
  108.  
  109.  
  110. // The bot now needs to collect information about users in the channel
  111.  
  112. print( "Succesfully joined " + FBS_CHAN + "!" );
  113. }
  114. }
  115. else if ( FBS_EVENT == "353" ) FBSSortNicks( sz );
  116. else if ( ( FBS_EVENT == "MODE" ) || ( FBS_EVENT == "NICK" ) || ( FBS_EVENT == "JOIN" ) || ( FBS_EVENT == "PART" ) || ( FBS_EVENT == "QUIT" ) ) FBS_BOT.Send( "NAMES :" + FBS_CHAN + "\n" );
  117. if ( FBS_CHANEVENT == FBS_CHAN )
  118. {
  119. // Grab the nick
  120. Nick = GetTok( line, "!", 1 ).slice( 1 );
  121. // Figure out what the command is
  122. Command = GetTok( line, " ", 4 );
  123. // Figure out what prefix was used
  124.  
  125. Prefix = Command.slice( 1 );
  126. Command = Command.slice( 1 );
  127.  
  128. // Figure out the text after the command
  129. if ( NumTok( line, " " ) > 4 ) Text = GetTok( line, " ", 5, Count );
  130. else Command = split( Command, "\r\n" )[ 0 ];
  131.  
  132. // Parse the command
  133. /*
  134. if ( ( Prefix == "!" ) && ( Count > 4 ) ) FBSIrcCommand( Nick, Command.tolower(), Text );
  135. else if ( ( Prefix == "!" ) && ( Count == 4 ) ) FBSIrcCommand( Nick, Command.tolower(), null );
  136.  
  137. */
  138. if (Nick && Command && Text) { FBSIrcCommand( Nick, Command, Text ); }
  139. else if (Nick && Command) { FBSIrcCommand( Nick, Command, null ); }
  140.  
  141. }
  142. }
  143. }
  144. function LevelTag(lvl) {
  145. lvl = (lvl ? lvl:0);
  146. switch (lvl) {
  147. case 2:
  148. return "Usuario";
  149. case 3:
  150. return "VIP";
  151. case 4:
  152. return "Moderador";
  153. case 5:
  154. return "Admin";
  155. case 6:
  156. return "Jefe";
  157. default:
  158. return "Major";
  159. }
  160. }
  161.  
  162. function lLevelTag(lvl) {
  163. lvl = (lvl ? lvl:0);
  164. switch (lvl) {
  165. case 2:
  166. return "11";
  167. case 3:
  168. return "7";
  169. case 4:
  170. return "3";
  171. case 5:
  172. return "4";
  173. case 6:
  174. return "12";
  175. default:
  176. return "5";
  177. }
  178. }
  179.  
  180. function FBSIrcCommand( user, cmd, text )
  181. {
  182. // none of this needs to be touched, it is to do with getting channel levels
  183. local NickInfo = FindNick( user ), level, tLevel;
  184. local s = 0, plr;
  185. if ( text ) { s = NumTok( text, " " ); plr = FindPlayer( text ); }
  186.  
  187. if ( NickInfo ) level = NickInfo.Level.tointeger();
  188. //---------------------------------------------------------------------------
  189.  
  190. if (cmd) {
  191. if (cmd.slice(0,1) == "." && cmd.len() > 1)
  192.  
  193. {
  194. local msg = "" + user + ": " + cmd.slice(1);
  195. if (text) msg = msg + " " + text;
  196. EchoMessage("[IRC] "+msg+"");
  197. Message("[#0000CC][IRC] [#ffffff]"+msg);
  198. print("[IRC]"+msg)
  199. }
  200. }
  201.  
  202.  
  203. // these are two example commands that you can base your other commands off.
  204.  
  205. else if ( cmd == "!players" )
  206. {
  207. local b = null, c = false;
  208. for ( local count = GetPlayers(), a = 0, plr; count && a < GetMaxPlayers(); a++ )
  209. {
  210. if ( !( plr = FindPlayer( a ) ) ) continue;
  211.  
  212. if ( plr )
  213. {
  214. if ( b ) b=b+", 4["+plr.ID+"] 14"+plr.Name
  215. else b = "4["+plr.ID+"] 14"+plr.Name
  216. count--;
  217. c = true;
  218. }
  219. }
  220. if ( c == true ) EchoMessage( "2> 1Players: 1[" + GetPlayers() + "/" + GetMaxPlayers() + "] " + " - " + b );
  221. else EchoMessage( "1> Players: [ There are no players ]" );
  222. }
  223.  
  224. }
  225.  
  226. //============================= FUNCIONES ====================================//
  227. function EMessage( text )
  228. {
  229. Message( text );
  230. EchoMessage( text );
  231. }
  232.  
  233. function EchoMessage( text )
  234. {
  235. FBS_BOT.Send( "PRIVMSG " + FBS_CHAN + " " + text + "\n" );
  236. }
  237.  
  238. function EchoNotice( nick, text )
  239. {
  240. FBS_BOT.Send( "NOTICE " + nick + " " + text + "\n" );
  241. }
  242.  
  243. function FBSSortNicks( szList )
  244. {
  245. local a = NumTok( szList, " " );
  246. local NickList = GetTok( szList, " ", 6, a ), i = 1;
  247.  
  248. FBS_NICKS <- array( 50, null );
  249.  
  250. while( GetTok( NickList, " ", i ) != "366" )
  251. {
  252. local levelnick = GetTok( NickList, " ", i ), nick = levelnick.slice( 1 ), level = levelnick.slice( 0, 1 );
  253. if ( level == ":" ) { level = nick.slice( 0, 1 ); nick = nick.slice( 1 ); }
  254. if ( level == "+" ) AddNewNick( nick, 2 );
  255. else if ( level == "%" ) AddNewNick( nick, 3 );
  256. else if ( level == "@" ) AddNewNick( nick, 4 );
  257. else if ( level == "&" ) AddNewNick( nick, 5 );
  258. else if ( level == "~" ) AddNewNick( nick, 6 );
  259. else AddNewNick( nick, 1 );
  260. i ++;
  261. }
  262. }
  263.  
  264. function AddNewNick( szName, iLevel )
  265. {
  266. local i = FindFreeNickSlot();
  267. if ( i != -1 )
  268. {
  269. FBS_NICKS[ i ] = FBSLIST();
  270. FBS_NICKS[ i ].AddNick( szName, iLevel );
  271. }
  272. }
  273.  
  274. function FindFreeNickSlot()
  275. {
  276. for ( local i = 0; i < FBS_NICKS.len(); i++ )
  277. {
  278. if ( !FBS_NICKS[ i ] ) return i;
  279. }
  280. return -1;
  281. }
  282.  
  283. function FindNick( szName )
  284. {
  285. for ( local i = 0; i < FBS_NICKS.len(); i++ )
  286. {
  287. if ( FBS_NICKS[ i ] )
  288. {
  289. if ( FBS_NICKS[ i ].Name == szName ) return FBS_NICKS[ i ];
  290. }
  291. }
  292. return null;
  293. }
  294.  
  295. function CmdLevelCheck( plrlvl, lvl )
  296. {
  297. if ( plrlvl >= lvl ) return true;
  298. else EchoMessage( "Error, No lvl" );
  299. }
  300.  
  301. function CmdIRCLevel( cmd )
  302. {
  303. local cmd = GetTok( cmd, "!", 1 );
  304. return ReadIniInteger( "Commands.ini", "IRC", cmd );
  305. }
  306.  
  307. function GetTok(string, separator, n, ...)
  308. {
  309. local m = vargv.len() > 0 ? vargv[0] : n,
  310. tokenized = split(string, separator),
  311. text = "";
  312. if (n > tokenized.len() || n < 1) return null;
  313. for (; n <= m; n++)
  314. {
  315. text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
  316. }
  317. return text;
  318. }
  319.  
  320. function NumTok(string, separator)
  321. {
  322. local tokenized = split(string, separator);
  323. return tokenized.len();
  324. local s = split(string, separator);
  325. return s.len();
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement