Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2. print "POE IRC Bot. Skeleton by Caaz.\n";
  3. print "You can add an optional NICK.\n";
  4. print "SERVER (Optional PORT NICK)\n";
  5. chomp($Connect = <STDIN>);
  6.  
  7. use POE::Component::IRC;
  8. use POE;
  9.  
  10. BOTVARS: {
  11. $BotNick = "Akemi"; # Nick
  12. $BotUser = "."; # Username "ident"
  13. $BotName = "a Perl bot. Werewolf Autoplay 3"; # Real Name
  14. $BotPass = "princesschan"; # Nickserv Password
  15. $Game{"Mode"} = "None";
  16. }
  17. $Connect = $Connect." ".$BotNick;
  18. $BotNick = (split / /, $Connect)[2];
  19. my ($irc) = POE::Component::IRC->spawn();
  20. POE::Session->create(inline_states => {
  21. _start => sub {
  22. $irc->yield(register => "all");
  23. $irc->yield( connect => {
  24. Nick => (split / /, $Connect)[2],
  25. Username => $BotUser,
  26. Ircname => $BotName,
  27. Server => (split / /, $Connect)[0],
  28. Port => (split / /, $Connect)[1],
  29. });
  30. },
  31. irc_001 => sub {
  32. $irc->yield(mode => $BotNick." +B");
  33. $irc->yield(privmsg => "Nickserv" => "id ".$BotPass);
  34. my $alarm_id = $irc->delay ( [ join => "#Wwolf" ], 2 ); ], 2 );
  35. },
  36. irc_error => sub {
  37. my ($kernel, $IRCWhat) = @_[KERNEL, ARG0];
  38. print $IRCWhat."\n";
  39. },
  40. irc_ctcp_action => sub {
  41. my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  42. $IRCWhere = $where->[0];
  43. print GetTime()."$IRCWhere > * ".(split /!/, $IRCWho)[0]." $IRCWhat\n";
  44. Bot("ACTION",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  45. },
  46. irc_join => sub {
  47. my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  48. print GetTime()."Join * ".(split /!/, $IRCWho)[0]." joins $IRCWhere\n";
  49. Bot("JOIN",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  50. },
  51. irc_invite => sub {
  52. my ($kernel, $IRCWho, $IRCWhere) = @_[KERNEL, ARG0, ARG1];
  53. print GetTime()."Invi * ".(split /!/, $IRCWho)[0]." invites you to $IRCWhere\n";
  54. Bot("INVITE", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere);
  55. },
  56. irc_kick => sub {
  57. my ($kernel, $IRCWho, $IRCWhere, $IRCWhoElse, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2, ARG3];
  58. print GetTime()."Kick * ".(split /!/, $IRCWho)[0]." kicks $IRCWhoElse out of $IRCWhere ($IRCWhat)\n";
  59. Bot("KICK",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhoElse,$IRCWhat);
  60. },
  61. irc_msg => sub {
  62. my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  63. $IRCWhere = $where->[0];
  64. print GetTime()."Priv\a> <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
  65. Bot("PRIVMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  66. },
  67. irc_nick => sub {
  68. my ($kernel, $IRCWho, $IRCWhoElse) = @_[KERNEL, ARG0, ARG1];
  69. print GetTime()."Nick * ".(split /!/, $IRCWho)[0]." changes nick to $IRCWhoElse\n";
  70. Bot("NICK", (split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhoElse);
  71. },
  72. irc_notice => sub {
  73. my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  74. $IRCWhere = $where->[0];
  75. print GetTime()."Noti <".(split /!/, $IRCWho)[0]."> $IRCWhat\n" if((split /!/, $IRCWho)[0] !~ /WolfBot/i);
  76. Bot("NOTICE",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  77. },
  78. irc_part => sub {
  79. my ($kernel, $IRCWho, $IRCWhere, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  80. print GetTime()."Part * ".(split /!/, $IRCWho)[0]." left channel $IRCWhere \(".$IRCWhat."\)\n";
  81. Bot("PART",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  82. },
  83. irc_public => sub {
  84. my ($kernel, $IRCWho, $where, $IRCWhat) = @_[KERNEL, ARG0, ARG1, ARG2];
  85. $IRCWhere = $where->[0];
  86. print GetTime()."$IRCWhere > <".(split /!/, $IRCWho)[0]."> $IRCWhat\n";
  87. Bot("CHANMSG",(split /!/, $IRCWho)[0],(split /!/, $IRCWho)[1],$IRCWhere,$IRCWhat);
  88. },
  89. irc_disconnected => sub { print "Disconnected.\n"; exit 1; }, # Ends on disconnect.
  90. },);
  91. #Powerplant,#Little_Cup,#darkisland,#chamoparty,#Finale,#SaintsOfVengeance,#wwolf
  92. sub Bot {
  93. $Event = $_[0];
  94. if($Event =~ /CHANMSG/) { $Com = "privmsg ".$_[3]." "; $UserMsg = $_[4]; $Where = $_[3]; }
  95. elsif($Event =~ /NOTICE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  96. elsif($Event =~ /PRIVMSG/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[4]; $Where = $_[1]; }
  97. elsif($Event =~ /INVITE/) { $Com = "notice ".$_[1]." "; $UserMsg = $_[3]; $Where = $_[1]; if ($UserMsg !~ /Spp/i) { $irc->yield(join => $UserMsg); }} # Joins on invite, if it's not spp. heh.
  98. elsif($Event =~ /JOIN/) { $Com = "notice ".$_[3]." "; $UserMsg = $_[3]; $Where = $_[1]; }
  99. $UserNick = Regexit($_[1]);
  100. $UserHost = $_[2];
  101. $UserMsg = POE::Component::IRC::Common::strip_formatting(POE::Component::IRC::Common::strip_color($UserMsg));
  102. if(($Where =~ /wwolf/i) || ($UserNick =~ /Wolfbot/i)) {
  103. if($Event =~ /(CHANMSG|NOTICE|PRIVMSG)/) {
  104. if(($UserMsg =~ /^($BotNick|Bots), Join/i) && ($WW{"Will Join"} !~ /No/i)) {
  105. $irc->yield(privmsg => "#WWolf" => "!Join");
  106. $WW{"Will Join"} = "No";
  107. $WW{"MyType"} = "Villager";
  108. }
  109. elsif(($UserMsg =~ /^$BotNick, Leave/i) && ($WW{"Will Join"} =~ /No/i)) {
  110. $irc->yield(part => "#WWolf" => "Invite me, and I will continue playing.");
  111. $WW{"Will Join"} = "Yes";
  112. while ( ($key, $value) = each %WW ) {
  113. $WW{$key} = "";
  114. }
  115. }
  116. elsif($UserMsg =~ /^$BotNick won,/i) {
  117. my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => "Woohoo! I won. :D" ], 1 );
  118. while ( ($key, $value) = each %WW ) {
  119. $WW{$key} = "";
  120. }
  121. }
  122. elsif($UserMsg =~ /^$BotNick lost,/i) {
  123. my $alarm_id = $irc->delay( [ privmsg => "#wwolf" => ";~; I didn't think I'd lose..." ], 1 );
  124. while ( ($key, $value) = each %WW ) {
  125. $WW{$key} = "";
  126. }
  127. }
  128. elsif($UserMsg =~ /^The game is over\.$|^Game cancelled\./i) {
  129. while ( ($key, $value) = each %WW ) {
  130. $WW{$key} = "";
  131. }
  132. }
  133. elsif($UserMsg =~ /^($BotNick|Bots), what are you/i) {
  134. if($WW{"MyType"} =~ /Wolf|Village Idiot/) {
  135. $irc->yield(privmsg => "#WWolf" => "I am a Villager.");
  136. }
  137. else {
  138. $irc->yield(privmsg => "#WWolf" => "I am a ".$WW{"MyType"}.".");
  139. }
  140. }
  141. elsif($UserMsg =~ /(.*?) (has joined|has started)/i) {
  142. if($1 =~ /$BotNick/) { return 0; }
  143. $WW{"Players"} = $WW{"Players"}.$1." ";
  144. @WWPlayers = split / /, $WW{"Players"};
  145. print "Updating players...\n".@WWPlayers."\n";
  146. }
  147. elsif($UserMsg =~ /^(.*) (has left the game|struggles vainly|was)/i) {
  148. $WW{"Players"} =~ s/$1 //igs;
  149. @WWPlayers = split / /, $WW{"Players"};
  150. print "Updating players...\n".@WWPlayers."\n";
  151. }
  152. elsif($UserMsg =~ /has cast their vote for (.*?)!/i) {
  153. $tring = $1;
  154. $WW{"Votes".Regexit($tring)}++;
  155. if(($WW{"Votes".Regexit($tring)} > $WW{"MostVoted"}) && (Regexit($tring) !~ /$WW{"MostVotedName"}/)) {
  156. $WW{"MostVoted"} = $WW{"Votes".Regexit($tring)};
  157. $WW{"MostVotedName"} = Regexit($tring);
  158. $irc->yield(privmsg => "WolfBot" => "vote ".$tring) if(int(rand(100)) > 60);
  159. }
  160. }
  161. elsif($UserMsg =~ /seconds to send your votes/i) {
  162. if($WW{"Vote"} !~ /^$/) {
  163. my $alarm_id = $irc->delay( [ privmsg => "WolfBot" => "vote ".$WW{"Vote"} ], 5 );
  164. }
  165. $WW{"Vote"} = "";
  166. if($WW{"MyType"} =~ /Village Idiot/i) {
  167. $WW{"Vote"} = $BotNick;
  168. }
  169. }
  170. if(($UserNick =~ /WolfBot/i) && ($Event =~ /(NOTICE|PRIVMSG|CHANMSG)/)) {
  171. if($UserMsg =~ /You are a wolf!/i) {
  172. $WW{"MyType"} = "Wolf";
  173. print "Wolf!";
  174. }
  175. elsif($UserMsg =~ /You are the finder!/i) {
  176. $WW{"MyType"} = "Finder";
  177. }
  178. elsif($UserMsg =~ /You are the seer!/i) {
  179. $WW{"MyType"} = "Seer";
  180. }
  181. elsif($UserMsg =~ /You are the doppleganger!/i) {
  182. $WW{"MyType"} = "Doppleganger";
  183. }
  184. elsif($UserMsg =~ /You are the angel!/i) {
  185. $WW{"MyType"} = "Angel";
  186. }
  187. elsif($UserMsg =~ /You are the Village Idiot!/i) {
  188. $WW{"MyType"} = "Village Idiot";
  189. my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $WWPlayers[int(rand(@WWPlayers))]." is Wolf." ], 50 );
  190. $WW{"Vote"} = $BotNick;
  191. }
  192. elsif($UserMsg =~ /into (a|an) (.*?)!/i) {
  193. $tring = $2;
  194. if($tring =~ /werewolf/i) { $WW{"MyType"} = "Wolf"; }
  195. else {
  196. $WW{"MyType"} = $tring;
  197. }
  198. }
  199. elsif($UserMsg =~ /You have 45/i) {
  200. if($WW{"MyType"} =~ /Wolf/i) {
  201. $irc->yield(privmsg => "wolfbot" => "kill ".$WWPlayers[int(rand(@WWPlayers))]);
  202. }
  203. elsif($WW{"MyType"} =~ /Seer/i) {
  204. foreach (@WWPlayers) {
  205. if($WW{"Targeted"} !~ /Regexit($_)/i){
  206. $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  207. $WW{"Target"} = $_;
  208. last;
  209. }
  210. }
  211. $irc->yield(privmsg => "wolfbot" => "see ".$WW{"Target"});
  212. }
  213. elsif($WW{"MyType"} =~ /Finder/i) {
  214. foreach (@WWPlayers) {
  215. if($WW{"Targeted"} !~ /Regexit($_)/i){
  216. $WW{"Targeted"} = $WW{"Targeted"}.Regexit($_);
  217. $WW{"Target"} = $_;
  218. last;
  219. }
  220. }
  221. $irc->yield(privmsg => "wolfbot" => "find ".$WW{"Target"});
  222. }
  223. if($WW{"MyType"} =~ /Doppleganger/i) {
  224. $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  225. $irc->yield(privmsg => "wolfbot" => "dopple ".$WW{"Target"});
  226. }
  227. if($WW{"MyType"} =~ /Angel/i) {
  228. $WW{"Target"} = $WWPlayers[int(rand(@WWPlayers))];
  229. $irc->yield(privmsg => "wolfbot" => "shield ".$WW{"Target"});
  230. }
  231. }
  232. elsif($UserMsg =~ /(.*?) is (a|an) (.*?)!/i) {
  233. $tring = $1;
  234. $tringt = $3;
  235. if($tringt =~ /Wolf/i) {
  236. my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Wolf." ], 5 );
  237. $WW{"Vote"} = $tring;
  238. }
  239. if($tringt =~ /Idiot/i) {
  240. my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." is Village idiot." ], 5 );
  241. }
  242. elsif($tringt =~ /Angel/i) {
  243. my $alarm_id = $irc->delay( [ privmsg => $tring => "I'm seer, and you're angel, right? Protect me, I'll keep looking for the wolf." ], 2 );
  244. }
  245. elsif($tringt =~ /Doppleganger/i) {
  246. my $alarm_id = $irc->delay( [ privmsg => $tring => "Dopple me for seer!" ], 2 );
  247. }
  248. }
  249. elsif($UserMsg =~ /(.*?) targetted (.*?)!/i) {
  250. $tring = $1;
  251. $tringt = $3;
  252. my $alarm_id = $irc->delay( [ privmsg => "#WWolf" => $tring." targetted ".$tringt."." ], 5 );
  253. $WW{"Vote"} = $tring;
  254. }
  255. elsif($UserMsg =~ /The (wolves|other wolves) are: (.*)/i) {
  256. @WWolfs = split /, /, $1;
  257. print "Updating players...\n";
  258. foreach (@WWolfs) {
  259. $WW{"Players"} =~ s/$_ //gs;
  260. @WWPlayers = split / /, $WW{"Players"};
  261. print "Updating players...\n".@WWPlayers."\n";
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. sub Regexit {
  269. ($Reg = $_[0]) =~ s/\\/\\\\/gs;
  270. $Reg =~ s/(\?|\(|\)|\||\[|\|\{|\}|\.)/\\$1/gs;
  271. $Reg =~ s/\*/\(\.\*\)/gs;
  272. return $Reg;
  273. }
  274. sub GetTime { # This is just for timestamps, just leave it.
  275. my($Sec, $Min, $Hour, $Day, $Mon, $Year, $WDay, $YDay) = localtime;
  276. my $APM = "AM";
  277. if($Hour > 12) { $Hour -= 12; $APM = "PM"; }
  278. if($Hour < 10) { $Hour = "0".$Hour; }
  279. if($Min < 10) { $Min = "0".$Min; }
  280. if($Sec < 10) { $Sec = "0".$Sec; }
  281. return "[ $Hour:$Min:$Sec $APM ] ";
  282. }
  283. # Caaz was here.
  284. $poe_kernel->run();
  285. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement