tc-14.pl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # This script responds with a comment each time someone in the channel says "clockbot"
  2. #
  3. # This script requires you to have the text file "clockbot" in your /home/user/.irssi/ directory
  4. #
  5. # cat ~/signatures/sig-natures | sed 's/^%$/####/;'| tr '\n' ' ' | sed 's/[[:space:]]\+/ /g;s/[[:space:]]####[[:space:]]/\n/g;' > ../../clockbot
  6. # asr - Gaétan RYCKEBOER - 2012-2014
  7. use Irssi;
  8. use vars qw($VERSION %IRSSI);
  9. use POSIX qw(strftime);
  10. use LWP::UserAgent;
  11. $VERSION = "1.2.4";
  12. %IRSSI = (
  13. author => 'pleia2',
  14. contact => 'lyz@princessleia.com ',
  15. name => 'TC-14',
  16. description => 'Protocol Droid, dedicated to Lautre.roots',
  17. license => 'GNU GPL v2 or later',
  18. url => 'http://www.lautre.net/',
  19. );
  20. # those 4 files contains random quotes. One per line.
  21. open ( CLOCKE, "<.irssi/randyes" ) or die "can't open randyes:$!\n";
  22. chomp( @randyes = <CLOCKE> );
  23. close CLOCKE;
  24. open ( CLOCKIE, "<.irssi/clockbot" ) or die "can't open clockbot:$!\n";
  25. chomp( @clockbot = <CLOCKIE> );
  26. close CLOCKIE;
  27. open ( CLOCKOK, "<.irssi/randok" ) or die "can't open clockbot:$!\n";
  28. chomp( @clockok = <CLOCKOK> );
  29. close CLOCKOK;
  30. open ( CLOCKPO, "<.irssi/quotes" ) or die "can't open clockbot:$!\n";
  31. chomp( @clockpo = <CLOCKPO> );
  32. close CLOCKPO;
  33. srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`);
  34. my $changefile="/home/tc-14/var/changelog";
  35. my $debug=0;
  36. my $bingo=0;
  37. my $last='';
  38. my $warn='';
  39. my @dad=("asr", "asr`", "asr_", "asr\\", "asr`_");
  40. my $timeout=30;
  41. my $warndate=time()-$timeout;
  42. Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
  43. 'tc_chans', '#flood #starwars'); #
  44. Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
  45. 'tc_admins', 'asr coin plop'); #
  46. Irssi::settings_add_str($IRSSI{name}, # default fifo_remote_file
  47. 'tc_logfile', '/home/tc-14/var/chan.log'); #
  48. my @chan=split m/ /, Irssi::settings_get_str("tc_chans");
  49. my @admin_chan=split m/ /, Irssi::settings_get_str("tc_admins");
  50. my $logfile=Irssi::settings_get_str("tc_logfile");
  51. sub in_array {
  52. my ($arr,$search_for) = @_;
  53. return grep {$search_for eq $_} @$arr;
  54. }
  55. sub event_join {
  56. my ($server, $data, $nick, $host) = @_;
  57. my ($target) = $data =~ /^:(.*)/;
  58. my $admin=0;
  59. if (in_array(@chan,$target) || in_array(@admin_chan,$target))
  60. {
  61. return;
  62. }
  63. foreach $father (@dad) {
  64. if ($father eq $nick) {
  65. $admin=1;
  66. }
  67. }
  68. foreach $father (@dad ) {
  69. if ($nick =~ /^$father$/i) {
  70. # $server->command ( "mode $target +v $nick" );
  71. my @messages=(
  72. "MSG $target Toi, $nick, je te connais, je t'ai deja vu quelque part...",
  73. "MSG $target Toi, $nick, je te connais, je t'ai deja vu quelque part...",
  74. "MSG $target Bonjour, Maître $nick",
  75. "action $target s'incline.",
  76. "action $target . o O ( Roh, v'la l'aut'guignol... )"
  77. );
  78. my $message=$messages[rand @messages];
  79. }
  80. print (">> $message -");
  81. $server->command ( $message );
  82. undef @messages;
  83. }
  84. # if ($nick =~ /^BirthdayBot$/i) {
  85. # $server->command ( "mode $target +o $nick" );
  86. # }
  87. }
  88. sub event_privmsg {
  89. my ($server, $data, $nick, $mask) =@_;
  90. my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
  91. #print ( "C:$target X:$text A:$admin D:$warndate L:$last W:$warn N:$nick D:$data" );
  92. sub send_server($$$$) {
  93. my ($action,$cible,$pseudo,$msg)=@_;
  94. $server->command ( "msg $target SWarn C:$cible X:$action A:$admin D:$warndate L:$last W:$warn N:$pseudo T:$msg" ) unless ($debug == 0);
  95. if (in_array(@chan,$target) || in_array(@admin_chan,$pseudo))
  96. {
  97. return;
  98. } else {
  99. if (($warndate + $timeout) < time()) {
  100. $warn='';
  101. $last='';
  102. }
  103. if (!($warn eq $pseudo)) {
  104. if ($last eq $pseudo) {
  105. $server->command ( "msg $cible $pseudo: Chut.");
  106. $warn=$nick;
  107. } else {
  108. $server->command ( "$action $cible $msg" );
  109. $last=$nick;
  110. }
  111. } else {
  112. $server->command ( "msg $cible $pseudo bloque pour $timeout" ) unless $debug=0;
  113. }
  114. $warndate=time();
  115. }
  116. }
  117. my $admin=0;
  118. if (in_array(@chan,$target) || in_array(@admin_chan,$target))
  119. {
  120. return;
  121. }
  122. foreach $father (@dad) {
  123. if ($father eq $nick) {
  124. $admin=1;
  125. }
  126. }
  127. my $locdate=time()-$warndate;
  128. if ( $text =~ /^!status/i ) {
  129. if ($admin == 1) {
  130. my $locdate=time()-$warndate;
  131. $server->command ( "msg $target S1 A:$admin D:$warndate L:$last W:$warn N:$nick WD:$locdate/$timeout");
  132. $server->command ( "msg $target S2 V:$VERSION D:$debug T:$text B:$bingo" );
  133. foreach $K (keys %bingovar) {
  134. $server->command ( "msg $target SB $K:$bingovar{$K}" );
  135. }
  136. }
  137. return 1;
  138. }
  139. if (($warn ne $nick) || ($locdate) > time()) {
  140. if ( $text =~ /^tc-14:/i ) {
  141. $clocky="J'cause pas aux cons, ca les instruit.";
  142. send_server("msg", $target, $nick, "$clocky");
  143. }
  144. elsif ( $text =~ /^tc-14/i ) {
  145. $clocky = $clockok[rand @clockok];
  146. send_server("msg", $target, $nick, "$nick: $clocky");
  147. }
  148. elsif ( $text =~ /^!password( .+)?/ ) {
  149. my $password ="";
  150. $length = $1;
  151. if ($1 eq '') { $length = 10; }
  152. elsif ($1 >60) { $length = 60; }
  153. elsif ($1 < 5 ) { $length = 5; }
  154. my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
  155. while (length($password) < $length) {
  156. $password .= substr($possible, (int(rand(length($possible)))), 1);
  157. }
  158. send_server("msg", $target, $nick, "$password");
  159. }
  160. elsif ( $text =~ /n *a *(i|!) *n/i ) {
  161. if ( ! ($target =~ /spip/ ) ) {
  162. $server->command ( "msg $target C'est trois petits nains qui vont à la mine." );
  163. $server->command ( "msg $target Le troisième prend la pelle." );
  164. $server->command ( "msg $target Le second prend la pioche." );
  165. $server->command ( "msg $target Et le premier ? Qu'est-ce qu'il prend ?" );
  166. #$last=$nick;
  167. }
  168. }
  169. elsif ( $text =~ /..o...a.s/i ) {
  170. if ( ! ($target =~ /spip/ ) ) {
  171. if (int(rand(10)) > 6) {
  172. send_server("msg", $target, $nick, "Good luck, mister Gorky");
  173. #$server->command ( "msg $target $clocky" );
  174. #$last=$nick;
  175. }
  176. }
  177. }
  178. elsif ( $text =~ /a........o.....g/i ) {
  179. $clocky = $clockok[rand @clockok];
  180. send_server("msg", $target, $nick, $clockok);
  181. }
  182. elsif ( $text =~ /poule|coq[^u]|porc |cochon |boeuf|taureau|t-rex|tyrannosaure|..?l..?phant|canard|lapin|mouche|caribou|vache /i ) {
  183. $clocky = "\\_o<";
  184. send_server("msg", $target, $nick, $clocky);
  185. }
  186. elsif ((1==2) && ( $text =~ /(^|[ \t-()])(fuck|foutre|cul|merde|salaud|salop.*|putain|shit)([ .,?!]|$)/i ) ) {
  187. $clocky = "se bouche les oreilles";
  188. send_server("action", $target, $nick, $clocky);
  189. }
  190. elsif ( $text =~ /(th[^ ]+orie|pragmatique|delirium|spongieux|postural|fonctionnellement|cathar|quadri|capillo|drosoph)/i ) {
  191. if ( ! ($target =~ /spip/ ) ) {
  192. if (!($warn eq $nick)) {
  193. $last=$nick;
  194. $clocky = "Coche la case.";
  195. if ($bingovar{$1} eq "coche") {$clocky = "deja coche"}
  196. else {
  197. $bingovar{$1} = "coche";
  198. $bingo++;
  199. }
  200. $server->command ( "action $target $clocky" );
  201. if ( $bingo > 3 ) {
  202. undef(%bingovar);
  203. $bingo=0; $clocky="FOUTAISES !";
  204. $server->command ( "msg $target $clocky" );
  205. $warn=$nick;
  206. }
  207. }
  208. }
  209. }
  210. elsif ( $text =~ /orval|landelin|kwak|duvel|guinness|chimay|bi..?re|leffe/i ) {
  211. $clocky = $randyes[rand @randyes];
  212. send_server("msg", $target, $nick, $clocky) unless ($nick =~ /edgard/i);
  213. }
  214. elsif ( $text =~ /^!help/i ) {
  215. $clocky = $randyes[rand @randyes];
  216. send_server("msg", $target, $nick, $clocky) unless ($nick =~ /edgard/i);
  217. }
  218. elsif ( $text =~ /fortune/i ) {
  219. $clocky = $clockbot[rand @clockbot];
  220. send_server("msg", $target, $nick, $clocky) unless ($nick =~ /edgard/i);
  221. }
  222. }
  223. if ($debug == 1) {
  224. $server->command ( "msg $target D1 A:$admin L:$last W:$warn N:$nick B:$bingo" );
  225. my $locdate=time()-$warndate;
  226. $server->command ( "msg $target D2 W:$warndate T1:".time." T2:$locdate" );
  227. }
  228. }
  229. Irssi::signal_add('event privmsg', 'event_privmsg');
  230. Irssi::signal_add("event join", "event_join");
  231. Irssi::signal_add("message public", "event_privmsg");
  232. print $IRSSI{"name"}." loaded $VERSION.";