Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.72 KB | None | 0 0
  1. /*
  2. Irc Echo Script
  3. by megdaOnE
  4. */
  5.  
  6. //---- Irc Data ----
  7.  
  8. const BotName = "AOSB";
  9. const BotPass = "Admin";
  10. const IRCServerIP = "85.17.189.153";
  11. const IRCServerPort = 6667;
  12. const EchoChannel = "#asdafd";
  13. const EchoPass = "";
  14. const USER = 1;
  15. const VOICE = 2;
  16. const HALFOP = 3;
  17. const OP = 4;
  18. const SOP = 5;
  19. const OWNER = 6;
  20. local IRCNicks = {};
  21.  
  22. //---- Functions ----
  23.  
  24. function LoadIRCEcho()
  25. {
  26. IRCBot <- NewSocket( "IRCProcess" );
  27. IRCBot.Connect( IRCServerIP, IRCServerPort );
  28. IRCBot.SetNewConnFunc( "IRCLogin" );
  29. }
  30.  
  31. function IRCProcess( Data )
  32. {
  33. local params = split( Data, " " );
  34. local Count = params.len(), Nick, Cmd, Prefix, Channel = EchoChannel;
  35. if ( params[ 0 ] == "PING" ) { SendSMsg( "PONG " + params[ 1 ] + "\n" ); SendSMsg( "NAMES :" + EchoChannel + "\n" ); }
  36. if ( params[ 1 ] == "353" ) IRCSaveNicks( Data );
  37. else if ( params[ 1 ] == "MODE" || params[ 1 ] == "NICK" || params[ 1 ] == "JOIN" || params[ 1 ] == "PART" || params[ 1 ] == "QUIT" ) SendSMsg( "NAMES :" + EchoChannel + "\n" );
  38. if ( params[ 1 ] == "PRIVMSG" && params[ 2 ].tolower() == Channel.tolower() )
  39. {
  40. if ( params[ 2 ].find( "#" ) == null ) return null;
  41. else
  42. {
  43. Nick = split( Data, "!" )[ 0 ].slice( 1 );
  44. Cmd = params[ 3 ];
  45. Prefix = Cmd.slice( 1, 2 );
  46. Cmd = Cmd.slice( 2 ).tolower();
  47. if ( Count > 4 && Prefix == "!" ) IRCCommands( Nick, Cmd, Data.slice( Data.find( Cmd ) + ( Cmd.len() + 1 ) ) );
  48. else if ( Count == 4 && Prefix == "!" ) IRCCommands( Nick, split( Cmd, "\r\n" )[ 0 ], null );
  49. }
  50. }
  51. else if ( params[ 1 ] == "KICK" && params[ 2 ].tolower() == Channel.tolower() ) SendSMsg( "JOIN " + Channel + " " + EchoPass + "\n" );
  52. else if ( params[ 1 ] == "001" )
  53. {
  54. SendSMsg( "PRIVMSG NICKSERV IDENTIFY " + BotPass + "\n" );
  55. SendSMsg( "JOIN " + EchoChannel + " " + EchoPass + "\n" );
  56.  
  57. }
  58. }
  59.  
  60. function IRCLogin()
  61. {
  62. SendSMsg( "USER " + BotName + " 0 * : " + BotName + " \n" );
  63. SendSMsg( "NICK " + BotName + "\n" );
  64. SendSMsg( "PRIVMSG NickServ IDENTIFY " + BotPass + "\n" );
  65. SendSMsg( "MODE " + BotName + " +B\n" );
  66. }
  67.  
  68. function EchoMessage( text )
  69. {
  70. SendSMsg( "PRIVMSG " + EchoChannel + " " + text + "\n" );
  71. }
  72.  
  73. function EMessage( text )
  74. {
  75. EchoMessage( text );
  76. Message( text.slice( 3 ) );
  77. }
  78.  
  79. /*function EMessage( text, ... )
  80. {
  81. EchoMessage( text );
  82. if ( vargv.len() < 1 ) Message( text.slice( 3 ) );
  83. else Message( text.slice( 3 ), vargv[ 0 ] );
  84. }*/
  85.  
  86. function UnloadIRCEcho()
  87. {
  88. if ( IRCBot )
  89. {
  90. SendSMsg( "QUIT " + BotName + "\n" );
  91. IRCBot.Delete();
  92. }
  93. }
  94.  
  95. function SendSMsg( msg )
  96. {
  97. try
  98. {
  99. if ( IRCBot ) IRCBot.Send( msg );
  100. }
  101. catch(E)
  102. {
  103. print( "Error Sending a message to the socket: " + E );
  104. return 1;
  105. }
  106. }
  107.  
  108. function IRCCommands( Nick, cmd, text )
  109. {
  110. local UserInfo, level, params;
  111. if ( !IRCNicks.rawin( Nick ) ) { IRCNewNick( Nick, 1 ); level = 1; }
  112. else { UserInfo = IRCNicks[ Nick ]; level = UserInfo.Level.tointeger(); }
  113.  
  114. if ( text ) text = text.slice( 0, text.len() - 2 );
  115.  
  116. if ( cmd == "say" )
  117. {
  118. if ( !text ) EchoMessage( "**4 Error - Correct Syntax:5 !" + cmd + " <Text>" );
  119. else EMessage( "12>> IRC: [" + GetIRCLevel( level ) + "] " + Nick + ": " + text + "." );
  120. }
  121.  
  122. else if ( cmd == "ping" )
  123. {
  124. if ( !text ) EchoMessage( "**4 Error - Correct Syntax:5 !" + cmd + " <nick/id>" );
  125. {
  126. local param = split( text, " " ), plr = GetPlayer( param[ 0 ] );
  127. if ( !plr ) EchoMessage( "4[Error] >> " + param[ 0 ] + " isn't connected." );
  128. else EchoMessage( "7>> Ping " + plr.Name + " - " + plr.Ping + "." );
  129. }
  130. }
  131.  
  132. else if ( cmd == "players" )
  133. {
  134. local b = null;
  135. for ( local a = 0; a < GetMaxPlayers(); a ++ )
  136. {
  137. local plr = FindPlayer( a );
  138. if ( plr )
  139. {
  140. if ( b ) b = b + " - 5" + plr.Name + " 14 [" + plr.ID + "]";
  141. else b = plr.Name + " 14[" + plr.ID + "]";
  142. }
  143. }
  144.  
  145. if ( b ) EchoMessage( "**2 Players Online: 5" + b );
  146. else EchoMessage( "5There Aren't Players Online." );
  147. }
  148.  
  149. else if ( cmd == "admins" )
  150. {
  151. local b = null;
  152. for ( local a = 0; a < GetMaxPlayers(); a ++ )
  153. {
  154. local plr = FindPlayer( a );
  155. if ( plr )
  156. {
  157. if ( GetPlayerLevel( plr ) >= 6 )
  158. {
  159. if ( b ) b = b + " - 13" + plr.Name + " 12[ " + LevelTag( GetPlayerLevel( plr ) ) + " ]";
  160. else b = plr.Name + " 12[ " + LevelTag( GetPlayerLevel( plr ) ) + " ]";
  161. }
  162. }
  163. }
  164.  
  165. if ( b ) EchoMessage( "7>> Admins's: 13" + b );
  166. else EchoMessage( "**5 No Admins Online." );
  167. }
  168.  
  169. else if ( cmd == "kick" )
  170. {
  171. if ( level < 4 ) EchoMessage( "4>> Only players with level 4 [ " + GetIRCLevel( 4 ) + " ] or high, have acces to this command." );
  172. else if ( !text ) EchoMessage( "6[Syntax] - The correct use: /c " + cmd + " <nick/id> <reason>." );
  173. else
  174. {
  175. local txt = NumTok( text, " " );
  176. if ( txt < 2 ) EchoMessage( "6[Syntax] - The correct use: /c " + cmd + " <nick/id> <reason>." );
  177. else
  178. {
  179. local plr = GetPlayer( GetTok( text, " ", 1 ) );
  180. if ( !plr ) EchoMessage( "6[Error] - Invalid nick/id, unknown player." );
  181. else
  182. {
  183. Message( "12>> IRC Admin " + Nick + " Kicked: " + plr.Name + ", ID: " + plr.ID + ", Reason:[ " + GetTok( text, " ", 2, txt ) + " ]." );
  184. KickPlayer( plr );
  185. }
  186. }
  187. }
  188. }
  189.  
  190. else if ( cmd == "ban" )
  191. {
  192. if ( level < 5 ) EchoMessage( "4>> Only players with level 5 [ " + GetIRCLevel( 5 ) + " ] or high, have acces to this command." );
  193. else if ( !text ) EchoMessage( "6[Syntax] - The correct use: /c " + cmd + " <nick/id> <reason>." );
  194. else
  195. {
  196. local txt = NumTok( text, " " );
  197. if ( txt < 2 ) EchoMessage( "6[Syntax] - The correct use: /c " + cmd + " <nick/id> <reason>." );
  198. else
  199. {
  200. local plr = GetPlayer( GetTok( text, " ", 1 ) );
  201. if ( !plr ) EchoMessage( "6[Error] - Invalid nick/id, unknown player." );
  202. else
  203. {
  204. QuerySQL( SQLDataBase, format( "REPLACE INTO Banneds ( IP, Name, User, Data, ByAdmin, Reason ) VALUES ( '%s', '%s', '%s', '%s', '%s', '%s' )", plr.IP, plr.Name.tolower(), plr.Name, GetFullTime(), Nick , GetTok( text, " ", 2, txt ) ) );
  205. EMessage( "12>> IRC Admin " + Nick + " Banned: " + plr.Name + ", ID: " + plr.ID + ", Reason:[ " + GetTok( text, " ", 2, txt ) + " ]." );
  206. KickPlayer( plr );
  207. }
  208. }
  209. }
  210. }
  211.  
  212. else if ( cmd == "setlevel" )
  213. {
  214. if ( level < 6 ) EchoMessage( "4>> Only players with level 6 [ " + GetIRCLevel( 6 ) + " ] or high, have acces to this command." );
  215. else if ( !text ) EchoMessage( "6[Syntax] >> The correct use: " + cmd + " <nick/id> <level>." );
  216. else
  217. {
  218. local txt = NumTok( text, " " );
  219. if ( txt < 2 ) EchoMessage( "6[Syntax] >> The correct use: " + cmd + " <nick/id> <level>." );
  220. else
  221. {
  222. local plr = GetPlayer( GetTok( text, " ", 1 ) );
  223. if ( !plr ) EchoMessage( "6[Error] - Invalid Nick/ID, unknown player." );
  224. else if ( !GetPlayerLevel( plr ) ) EchoMessage( "6[Error] - " + plr.Name + " not registered!" );
  225. else
  226. {
  227. local lvl = GetTok( text, " ", 2, txt );
  228. if ( !IsNum( lvl ) ) EchoMessage( "6[Error] - Invalid level, type numbers to level." );
  229. else
  230. {
  231. SetPlayerLevel( plr, lvl.tointeger() );
  232. EMessage( "12>> IRC Admin " + Nick + " set " + plr.Name + "'s level administration to [ " + lvl.tointeger() + " ] [ " + LevelTag( lvl.tointeger() ) + " ]." );
  233. }
  234. }
  235. }
  236. }
  237. }
  238.  
  239.  
  240. else if ( cmd == "restart" )
  241. {
  242. if ( level >= OP ) { EchoMessage( COL_RED + "***Restarting Echo Bot please wait some seconds***" ); NewTimer( "Reconnect", 1000, 1 ); }
  243. else EchoMessage( COL_RED + "Error - You don't have the needed level to restart the echo bot" );
  244. }
  245. }
  246.  
  247. function IRCSaveNicks( List )
  248. {
  249. local a = NumTok( List, " " ), NickList = GetTok( List, " ", 6, a ), i = 1;
  250. local Nicks = split( NickList, " " );
  251. while( Nicks[ i-1 ] != "366" )
  252. {
  253. local nick = Nicks[ i-1 ].slice( 1 ), level = Nicks[ i-1 ].slice( 0, 1 );
  254.  
  255. if ( level == ":" ) { level = nick.slice( 0, 1 ); nick = nick.slice( 1 ); }
  256.  
  257. if ( level == "+" ) IRCNewNick( nick, 2 );
  258. else if ( level == "%" ) IRCNewNick( nick, 3 );
  259. else if ( level == "@" ) IRCNewNick( nick, 4 );
  260. else if ( level == "&" ) IRCNewNick( nick, 5 );
  261. else if ( level == "~" ) IRCNewNick( nick, 6 );
  262. else IRCNewNick( Nicks[ i-1 ], 1 );
  263. i ++;
  264. }
  265. }
  266.  
  267. function IRCNewNick( Name, Level )
  268. {
  269. IRCNicks[ Name ] <- IRCNickz();
  270. IRCNicks[ Name ].SaveNickInfo( Name, Level );
  271. }
  272.  
  273. class IRCNickz
  274. {
  275. Name = null;
  276. Level = 1;
  277. }
  278.  
  279. function IRCNickz::SaveNickInfo( Nick, IRCLevel )
  280. {
  281. Name = Nick;
  282. Level = IRCLevel;
  283. }
  284.  
  285. function GetIRCLevel( Level )
  286. {
  287. local Name = "User";
  288. switch( Level )
  289. {
  290. case 1:
  291. Name = "User";
  292. break;
  293. case 2:
  294. Name = "Member";
  295. break;
  296. case 3:
  297. Name = "Moderator";
  298. break;
  299. case 4:
  300. Name = "Admin";
  301. break;
  302. case 5:
  303. Name = "Management";
  304. break;
  305. case 6:
  306. Name = "Owner Server";
  307. break;
  308. }
  309. return Name;
  310. }
  311.  
  312. function Reconnect()
  313. {
  314. UnloadIRCEcho();
  315. NewTimer( "LoadIRCEcho", 1600, 1 );
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement