Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.73 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Net::IRC;
  4.  
  5. $server = 'irc.nightstar.net';
  6. $port = 6667;
  7. $channel = '#Test,#Exalted,#DuelField,#SpaceRPG';
  8. #$channel = '#test';
  9. $botnick = 'PainBot';
  10. #$botnick = 'TestBot';
  11. $botuname = 'painbot';
  12. $password = 'foobar';
  13. $botadmin = 'AnnoDomini';
  14. $descript = 'AD\'s Other DiceBot';
  15. $version = '0.32-23072011';
  16. $maxline = 400;
  17. $state = 0; # 1 connected, 0 disconnected
  18. $liar_players = "";
  19. $liar_results = "";
  20.  
  21. $irc = new Net::IRC;
  22.  
  23. $conn = $irc->newconn(Nick => $botnick,
  24. Server => $server,
  25. Port => $port,
  26. Username => $botuname,
  27. Ircname => $descript);
  28.  
  29. $conn->add_global_handler('376', \&on_connect);
  30. $conn->add_global_handler('disconnect', \&on_disconnect);
  31. $conn->add_global_handler('kick', \&on_kick);
  32. $conn->add_global_handler('msg', \&on_priv);
  33. $conn->add_global_handler('cversion', \&on_ctcp_version);
  34. $conn->add_global_handler('public', \&on_public);
  35. $conn->add_global_handler('invite', \&on_invite);
  36. $conn->add_global_handler('cjoin', \&on_ctcp_join);
  37. $conn->add_global_handler('cpart', \&on_ctcp_part);
  38.  
  39. print STDERR "PainBot v".$version." started.\n";
  40. $irc->start;
  41.  
  42. sub on_ctcp_join {
  43. $self = shift;
  44. $event = shift;
  45. foreach $arg ($event->args) {
  46. $chan = $arg;
  47. $self->join($chan);
  48. print STDERR "Joining $chan.\n";
  49. }
  50. }
  51.  
  52. sub on_ctcp_part {
  53. $self = shift;
  54. $event = shift;
  55. foreach $arg ($event->args) {
  56. $self->part($chan);
  57. print STDERR "Parting $chan.\n";
  58. }
  59. }
  60.  
  61. sub on_connect {
  62. $self = shift;
  63. $self->privmsg('nickserv', "identify $password");
  64. $self->join($channel);
  65. $state = 1;
  66. print STDERR "Connected to " . $server . ".\n";
  67. }
  68.  
  69. sub on_disconnect {
  70. $self = shift;
  71. $state = 0;
  72. while ($state == 0) {
  73. $self->connect();
  74. sleep 30;
  75. }
  76. }
  77.  
  78. sub on_kick {
  79. $self = shift;
  80. $event = shift;
  81. print STDERR "Kicked by ".$event->nick.".\n";
  82. }
  83.  
  84. sub on_priv {
  85. $self = shift;
  86. $event = shift;
  87. handle_message($self,$event,$event->nick);
  88. }
  89.  
  90. sub on_public {
  91. $self = shift;
  92. $event = shift;
  93. handle_message($self,$event,$event->to);
  94. }
  95.  
  96. sub handle_message {
  97. $self = shift;
  98. $event = shift;
  99. $dest = shift;
  100.  
  101. foreach $arg ($event->args) {
  102. if ($arg =~ /^!die/i) {
  103. if ($event->nick eq $botadmin) {
  104. $self->quit("I return to the Wheel of Suffering.");
  105. print STDERR "Received shutdown command. Exiting.\n";
  106. exit 0;
  107. }
  108. } elsif ($arg =~ /^!ping/i) {
  109. $self->privmsg($dest, 'pong!');
  110. print STDERR "Ping command activated by ".$event->nick." in $dest.\n";
  111. } elsif ($arg =~ /^!version/i) {
  112. $self->privmsg($dest, 'PainBot v' . $version . ' by AnnoDomini.');
  113. print STDERR "Version command activated by ".$event->nick." in $dest.\n";
  114. } elsif ($arg =~ /^!roll\s+/i) {
  115. $expression = substr($arg,6,$maxline);
  116. command_roll($self,$dest,$event->nick,$expression);
  117. print STDERR "Rolling $expression for ".$event->nick." in $dest.\n";
  118. } elsif ($arg =~ /^!help/i) {
  119. $expression = substr($arg,6,$maxline);
  120. command_help($self,$dest,$event->nick,$expression);
  121. print STDERR "Help requested by ".$event->nick." in $dest.\n";
  122. } elsif ($arg =~ /^!exalted\s+/i) {
  123. $expression = substr($arg,9,$maxline);
  124. dicepool_roll($self,$dest,$event->nick,"exalted",$expression);
  125. print STDERR "Rolling Exalted dice for ".$event->nick." in $dest.\n";
  126. } elsif ($arg =~ /^!sr3\s+/i) {
  127. $expression = substr($arg,5,$maxline);
  128. dicepool_roll($self,$dest,$event->nick,"sr3",$expression);
  129. print STDERR "Rolling SR3 dice for ".$event->nick." in $dest.\n";
  130. } elsif ($arg =~ /^!nwod\s/i) {
  131. $expression = substr($arg,6,$maxline);
  132. dicepool_roll($self,$dest,$event->nick,"nwod",$expression);
  133. print STDERR "Rolling nWoD dice for ".$event->nick." in $dest.\n";
  134. } elsif ($arg =~ /^!space\s+/i) {
  135. $expression = substr($arg,7,$maxline);
  136. dicepool_roll($self,$dest,$event->nick,"space",$expression);
  137. print STDERR "Rolling Space dice for ".$event->nick." in $dest.\n";
  138. } elsif ($arg =~ /^!liar\s+/i) {
  139. $expression = substr($arg,6,$maxline);
  140. command_liar($self,$dest,$event->nick,$expression);
  141. print STDERR "Liar game operation for ".$event->nick." in $dest.\n";
  142. } elsif ($arg =~ /^!twilight\s+/i) {
  143. $expression = substr($arg,10,$maxline);
  144. dicepool_roll($self,$dest,$event->nick,"twilight",$expression);
  145. print STDERR "Twilight 2013 roll for ".$event->nick." in $dest.\n";
  146. } elsif ($arg =~ /^!join\s+/i) {
  147. $expression = substr($arg,6,$maxline);
  148. command_join($self,$expression);
  149. print STDERR "Join request in $dest.\n";
  150. } elsif ($arg =~ /^!part\s+/i) {
  151. $expression = substr($arg,6,$maxline);
  152. command_part($self,$expression);
  153. print STDERR "Part request in $dest.\n";
  154. } else {
  155. if (is_shorthand($arg) == 1) {
  156. $expression = substr($arg,1,$maxline);
  157. command_roll($self,$dest,$event->nick,$expression);
  158. print STDERR "Rolling $expression for ".$event->nick." in $dest.\n";
  159. }
  160. }
  161. }
  162. }
  163.  
  164. sub command_liar {
  165. $self = shift;
  166. $dest = shift;
  167. $nick = shift;
  168. $args = shift;
  169.  
  170. if ($args =~ /^reset/i) {
  171. $liar_players = "";
  172. $liar_results = "";
  173. $self->privmsg($dest, "Liar game reset.");
  174. } elsif ($args =~ /^add\s+/i) {
  175. $liar_players = substr($args,4,$maxline);
  176. $self->privmsg($dest, "Liar players added.");
  177. } elsif ($args =~ /^roll/i) {
  178. $explength = length($liar_players);
  179. $lastoperator = -1;
  180. for ($pos = 0;$pos<$explength;$pos++) {
  181. $curchar = substr($liar_players,$pos,1);
  182. if ($curchar =~ /,/ || $pos == $explength-1) {
  183. if ($pos == $explength-1) {
  184. $currentnick = substr($liar_players,$lastoperator+1,$maxline);
  185. } else {
  186. $currentnick = substr($liar_players,$lastoperator+1,$pos-$lastoperator-1);
  187. }
  188. $lastoperator = $pos;
  189. $currentroll = parse_one_roll("5d6");
  190. $currentroll =~ s/\+/ /go;
  191. $currentroll =~ s/\(//go;
  192. $currentroll =~ s/\)//go;
  193. $liar_results = $liar_results . " " .$currentroll;
  194. $self->privmsg($currentnick, "You rolled: $currentroll.");
  195. }
  196. }
  197. $liar_results = ltrim($liar_results);
  198. } elsif ($args =~ /^show/i) {
  199. $countlen = length($liar_results);
  200. if ($countlen > $maxline) { $snip = 1;} else { $snip = 0;}
  201. $ones = 0; $twos = 0; $tres = 0; $fors = 0; $fivs = 0; $sixs = 0;
  202. for ($i = 0;$i<$countlen;$i++) {
  203. $curchar = substr($liar_results,$i,1);
  204. if ($curchar =~ /1/) { $ones++;}
  205. if ($curchar =~ /2/) { $twos++;}
  206. if ($curchar =~ /3/) { $tres++;}
  207. if ($curchar =~ /4/) { $fors++;}
  208. if ($curchar =~ /5/) { $fivs++;}
  209. if ($curchar =~ /6/) { $sixs++;}
  210. }
  211. if ($snip == 0) { $liardice = $liar_results; } else { $liardice = "(many dice)"; }
  212. $self->privmsg($dest, "Liar results: $liardice (\x02".$ones."x1s, ".$twos."x2s, ".$tres."x3s, ".$fors."x4s, ".$fivs."x5s, ".$sixs."x6s\x02).");
  213. }
  214. }
  215.  
  216. sub command_help {
  217. $self = shift;
  218. $dest = shift;
  219. $nick = shift;
  220. $topic = shift;
  221. if (length($topic) == 0) {
  222. $output = "You have reached the help function of the PainBot, v$version, by AnnoDomini. Topics covered: general, roll, exalted, sr3, nwod, space, liar, twilight.";
  223. } else {
  224. $output = "No manual entry found.";
  225. }
  226. if ($topic =~ /general/i) {
  227. $output = "In the dicepool-using commands, repetitions are capped at 30, while dice are capped at 200. In the generic roller, repetitions are capped at 30, and dice are capped at 1000. In both, automatic detail-hiding is in effect if the result would cause a flood.";
  228. }
  229. if ($topic =~ /roll/i) {
  230. $output = "The generic dice roller function. Flags: h (drop high), l (drop low), f (floating reroll). Syntax: !roll <dice expression>[flags][,repetitions][:comment]";
  231. }
  232. if ($topic =~ /exalted/i) {
  233. $output = "The Exalted 2e dice roller function. Flags: a, b, l, m (10s don't count double), f (subtracts 1 die from each successive roll). Syntax: !exalted <dice pool> [<target number> [<repetitions> [<external modifier>]]][:comment]";
  234. }
  235. if ($topic =~ /sr3/i) {
  236. $output = "The Shadowrun 3e dice roller function. Syntax: !sr3 <dice pool> [<target number> [<repetitions>]][:comment]";
  237. }
  238. if ($topic =~ /nwod/i) {
  239. $output = "The New World of Darkness dice roller function. Flags: c (chance roll), n (no floating reroll). Syntax: !nwod <dice pool>[flags] [repetitions][:comment]";
  240. }
  241. if ($topic =~ /space/i) {
  242. $output = "The dice roller function for Reiver's Space Game. Syntax: !space <dice pool> [<target number> [repetitions]][:comment]";
  243. }
  244. if ($topic =~ /liar/i) {
  245. $output = "Assists in playing a game of Liar. To use, reset the game, add players, then roll. Players will be issued PMs with their rolls. When a player's statement is challenged, show. The list of player nicknames is comma-delimited. Syntax: !liar reset; !liar add <nick>[,nicks]; !liar roll; !liar show";
  246. }
  247. if ($topic =~ /twilight/i) {
  248. $output = "Twilight 2013 dice roller function. Uses d16s instead of d20s. Flags: h (take highest), l (take lowest). Syntax: !twilight <dice pool><flag> [<target number> [<repetitions>]][:comment]";
  249. }
  250. $self->privmsg($dest, $output);
  251. }
  252.  
  253. sub is_shorthand { # needs more detections
  254. $input = shift;
  255. if ($input =~ /^!d/i) { return 1; }
  256. if ($input =~ /^!\d/i) { return 1; }
  257. if ($input =~ /^!\(/i) { return 1; }
  258. return 0;
  259. }
  260.  
  261. sub command_part {
  262. $self = shift;
  263. $chan = shift;
  264. $self->part($chan);
  265. print STDERR "Parting " . $chan . ".\n";
  266. }
  267.  
  268. sub command_join {
  269. $self = shift;
  270. $chan = shift;
  271. $self->join($chan);
  272. print STDERR "Joining " . $chan . ".\n";
  273. }
  274.  
  275. sub on_ctcp_version {
  276. $self = shift;
  277. $event = shift;
  278. $self->ctcp_reply($event->nick,'PainBot v' . $version . ' by AnnoDomini.');
  279. print STDERR "Received and replied to CTCP VERSION from " . $event->nick . ".\n";
  280. }
  281.  
  282. sub dicepool_roll {
  283. $self = shift;
  284. $dest = shift;
  285. $nick = shift;
  286. $ruleset = shift;
  287. $args = shift;
  288. $output = "[$nick] rolled ";
  289. if ($args =~ /:/) {
  290. $colonpos = index $args,':';
  291. $comment = "\"". trim(substr($args,$colonpos+1,$maxline)) ."\": ";
  292. $dicepoolexpression = substr($args,0,$colonpos);
  293. } else {
  294. $comment = "";
  295. $dicepoolexpression = $args;
  296. }
  297. if ($ruleset =~ /exalted/i) {
  298. ($dice,$tn,$reps,$ext) = split(/ /,$dicepoolexpression);
  299. if (($dice =~ /a/i) || ($dice =~ /b/i) || ($dice =~ /l/i) || ($dice =~ /m/i)) {
  300. $tensexplode = 0;
  301. } else {
  302. $tensexplode = 1;
  303. }
  304. if ($dice =~ /f/i) { $flurry = 1; } else { $flurry = 0; }
  305. if (length($tn) == 0) { $tn = 7; }
  306. if ($tn < 1) { $tn = 1; }
  307. if ($tn > 10) { $tn = 10; }
  308. if (length($ext) == 0) { $ext = 0; }
  309. } elsif ($ruleset =~ /nwod/i) {
  310. ($dice,$reps) = split(/ /,$dicepoolexpression);
  311. if ($dice =~ /n/) { $tensexplode = 0; } else { $tensexplode = 1; }
  312. if ($dice =~ /c/) { $tn = 10; } else { $tn = 8; }
  313. } elsif ($ruleset =~ /sr3/i) {
  314. ($dice,$tn,$reps) = split(/ /,$dicepoolexpression);
  315. if (length($tn) == 0) { $tn = 4; }
  316. if ($tn < 1) { $tn = 1; }
  317. } elsif ($ruleset =~ /space/i) {
  318. ($dice,$tn,$reps) = split(/ /,$dicepoolexpression);
  319. $sixesexplode = 1;
  320. if (length($tn) == 0) { $tn = 4; }
  321. if ($tn < 1) { $tn = 1; }
  322. if ($tn > 6) { $tn = 6; }
  323. } elsif ($ruleset =~ /twilight/i) {
  324. ($dice,$tn,$reps) = split(/ /,$dicepoolexpression);
  325. if ($dice =~ /l/i) {
  326. $takelowest = 1;
  327. } elsif ($dice =~ /h/i) {
  328. $takelowest = 0;
  329. } else {
  330. $takelowest = 1;
  331. }
  332. if (length($tn) == 0) { $tn = 6; }
  333. if ($tn < 1) { $tn = 1; }
  334. if ($tn > 20) { $tn = 20; }
  335. }
  336. $dice =~ s/a//ig; $dice =~ s/m//ig; $dice =~ s/l//ig; $dice =~ s/b//ig; $dice =~ s/f//ig; #exalted
  337. $dice =~ s/n//ig; $dice =~ s/c//ig; #nwod
  338. $temp = "("; $successes = "";
  339. $measure = ""; $bumps = -1; $worst = 0; # twilight
  340. if (($reps < 1) || (length($reps) == 0)) { $reps = 1; }
  341. if ($reps > 30) { $reps = 30; }
  342. if ($dice > 200) { $dice = 200; }
  343. if (($dice < 1) || (length($dice) == 0)) { $dice = 1; }
  344. if ($dice * $reps > $maxline / 3) { $snip = 1; } else { $snip = 0; }
  345. for ($rep = 0;$rep<$reps;$rep++) {
  346. $currentsuccesses = 0 + $ext;
  347. for ($die = 0;$die<$dice;$die++) {
  348. if ($ruleset =~ /exalted/i) {
  349. $current = int(rand(10))+1;
  350. if ($current >= $tn) {
  351. $currentsuccesses++;
  352. if (($tensexplode == 1) && ($current == 10)) {
  353. $currentsuccesses++;
  354. }
  355. }
  356. $temp = $temp . $current . " ";
  357. } elsif ($ruleset =~ /nwod/i) {
  358. if ($tensexplode == 1) {
  359. do {
  360. $current = int(rand(10))+1;
  361. if ($current >= $tn) {
  362. $currentsuccesses++;
  363. }
  364. $temp = $temp . $current . " ";
  365. } while ($current == 10);
  366. } else {
  367. $current = int(rand(10))+1;
  368. if ($current >= $tn) {
  369. $currentsuccesses++;
  370. }
  371. $temp = $temp . $current . " ";
  372. }
  373. } elsif ($ruleset =~ /sr3/i) {
  374. $current = 0;
  375. do {
  376. $now = int(rand(6))+1;
  377. $current = $current + $now;
  378. } while ($now == 6);
  379. if ($current >= $tn) {
  380. $currentsuccesses++;
  381. }
  382. $temp = $temp . $current . " ";
  383. } elsif ($ruleset =~ /space/i) {
  384. if ($sixesexplode == 1) {
  385. do {
  386. $current = int(rand(6))+1;
  387. if ($current >= $tn) {
  388. $currentsuccesses++;
  389. }
  390. if ($current == 6) {
  391. $temp = $temp . "\x02" . $current . "\x02 ";
  392. } else {
  393. $temp = $temp . $current . " ";
  394. }
  395. } while ($current == 6);
  396. } else {
  397. $current = int(rand(6))+1;
  398. if ($current >= $tn) {
  399. $currentsuccesses++;
  400. }
  401. if ($current == 6) {
  402. $temp = $temp . "\x02" . $current . "\x02 ";
  403. } else {
  404. $temp = $temp . $current . " ";
  405. }
  406. }
  407. } elsif ($ruleset =~ /twilight/i) {
  408. $current = int(rand(16))+1;
  409. if ($takelowest == 1) {
  410. if ($current <= $tn) {
  411. if (length($measure) == 0) {
  412. $measure = $tn-$current;
  413. } elsif ($tn-$current >= $measure) {
  414. $measure = $tn-$current;
  415. }
  416. $bumps++;
  417. } else {
  418. if (length($measure) == 0) {
  419. $measure = $tn-$current;
  420. } elsif ($tn-$current >= $measure) {
  421. $measure = $tn-$current;
  422. }
  423. }
  424. } else {
  425. if ($current > $worst) { $worst = $current; }
  426. }
  427. $temp = $temp . $current . " ";
  428. }
  429. }
  430. if ($ruleset =~ /twilight/i) {
  431. if ($measure < 0) { $bumps = 0; }
  432. if ($takelowest == 0) { $measure = $tn-$worst; $bumps = 0; }
  433. $measure = $measure + ($bumps * 2);
  434. $successes = $successes . $measure . "; ";
  435. $measure = ""; $bumps = -1; $worst = 0;
  436. } else {
  437. $successes = $successes . $currentsuccesses . "; ";
  438. }
  439. $temp = substr($temp,0,-1) . "; ";
  440. if ($flurry == 1 && $ruleset =~ /exalted/i) {
  441. $dice = $dice - 1;
  442. }
  443. }
  444. $temp = substr($temp,0,-2) . ")";
  445. if ($ruleset =~ /exalted/i) {
  446. if ($ext == 0) {
  447. $suxnote = "";
  448. } elsif ($ext > 0) {
  449. $suxnote = " +$ext";
  450. } else {
  451. $suxnote = " $ext";
  452. }
  453. }
  454. if ($snip == 1) {
  455. $temp = "(many dice)";
  456. }
  457. if ($ruleset =~ /exalted/i) {
  458. $output = $output . $comment . $temp . ". Successes (TN " . $tn . ")$suxnote = \x02" . substr($successes,0,-2) . "\x02.";
  459. } elsif ($ruleset =~ /nwod/i) {
  460. $output = $output . $comment . $temp . ". Successes (TN " . $tn . ") = \x02" . substr($successes,0,-2) . "\x02.";
  461. } elsif ($ruleset =~ /sr3/i) {
  462. $output = $output . $comment . $temp . ". Successes (TN " . $tn . ") = \x02" . substr($successes,0,-2) . "\x02.";
  463. } elsif ($ruleset =~ /space/i) {
  464. $output = $output . $comment . $temp . ". Successes (TN " . $tn . ") = \x02" . substr($successes,0,-2) . "\x02.";
  465. } elsif ($ruleset =~ /twilight/i) {
  466. $output = $output . $comment . $temp . ". Margin(s) (TN " . $tn . ") = \x02" . substr($successes,0,-2) . "\x02.";
  467. }
  468.  
  469. $self->privmsg($dest,$output);
  470. }
  471.  
  472. sub command_roll {
  473. $self = shift;
  474. $dest = shift;
  475. $nick = shift;
  476. $args = shift;
  477. $output = "[$nick] rolled ";
  478. $totals = "";
  479. if ($args =~ /:/) {
  480. $colonpos = index $args,':';
  481. $comment = trim(substr($args,$colonpos+1,$maxline));
  482. $expressionwithreps = substr($args,0,$colonpos);
  483. } else {
  484. $comment = $args;
  485. $expressionwithreps = $args;
  486. }
  487. $output .= "\"$comment\": ";
  488. if ($expressionwithreps =~ /,/) {
  489. $commapos = index $expressionwithreps,',';
  490. $repetitions = alltrim(substr($expressionwithreps,$commapos+1,$maxline));
  491. $expression = alltrim(substr($expressionwithreps,0,$commapos));
  492. } else {
  493. $repetitions = 1;
  494. $expression = alltrim($expressionwithreps);
  495. }
  496. $expression =~ s/\^/\*\*/; # legacy
  497. if ($repetitions < 0) { $repetitions = 1; }
  498. if ($repetitions > 30) { $repetitions = 30; }
  499. $explength = length($expression);
  500. $expcopy = $expression;
  501. $mathableresult = "";
  502. for ($rep = 0;$rep<$repetitions;$rep++) { # rep loop
  503. $lastoperator = -1;
  504. for ($pos = 0;$pos<$explength;$pos++) { # string parsing
  505. $curchar = substr($expression,$pos,1);
  506. if (is_operator($curchar) == 1 || $pos == $explength-1) {
  507. if ($pos == $explength-1) {
  508. $mathableresult .= parse_one_roll(substr($expression,$lastoperator+1,$maxline));
  509. } else {
  510. $mathableresult .= parse_one_roll(substr($expression,$lastoperator+1,$pos-$lastoperator-1)) . $curchar;
  511. }
  512. $lastoperator = $pos;
  513. }
  514. }
  515. $output .= "$mathableresult, ";
  516. $totals .= eval($mathableresult)." ";
  517. $mathableresult = "";
  518. }
  519. $output = substr($output,0,-2).". Total: \x02".substr($totals,0,-1)."\x02.";
  520.  
  521. $self->privmsg($dest, $output);
  522.  
  523. }
  524.  
  525. sub is_operator {
  526. $input = shift;
  527. if ($input eq '+') { return 1; }
  528. if ($input eq '-') { return 1; }
  529. if ($input eq '*') { return 1; }
  530. if ($input eq '/') { return 1; }
  531. if ($input eq '^') { return 1; }
  532. if ($input eq '%') { return 1; }
  533. if ($input eq '(') { return 1; }
  534. if ($input eq ')') { return 1; }
  535. return 0;
  536. }
  537.  
  538. sub parse_one_roll {
  539. $args = shift;
  540. $dpos = index lc($args),'d';
  541. if ($dpos == -1) { return $args; }
  542. if ($args =~ /l/i) { # l
  543. $droplow = 1;
  544. $args =~ s/l//ig;
  545. } else {
  546. $droplow = 0;
  547. }
  548. if ($args =~ /h/i) { # h
  549. $drophigh = 1;
  550. $args =~ s/h//ig;
  551. } else {
  552. $drophigh = 0;
  553. }
  554. if ($args =~ /f/i) { # f
  555. $floating = 1;
  556. $args =~ s/f//ig;
  557. } else {
  558. $floating = 0;
  559. }
  560. if ($dpos == 0) {
  561. $nrofdice = 1;
  562. } else {
  563. $nrofdice = substr($args,0,$dpos);
  564. if ($nrofdice == 0) {
  565. $nrofdice = 1;
  566. }
  567. if ($nrofdice > 1000) {
  568. $nrofdice = 1000;
  569. }
  570. }
  571. $diesize = substr($args,$dpos+1,$maxline);
  572. if ($nrofdice * length($diesize) > ($maxline / 3)) {
  573. $snip = 1;
  574. } else {
  575. $snip = 0;
  576. }
  577. $result = '('; $highest = 0; $lowest = $diesize+1;
  578. for ($i = 0;$i<$nrofdice;$i++) {
  579. do {
  580. $current = int(rand($diesize))+1;
  581. if (($droplow == 1) && ($current < $lowest)) { $lowest = $current; }
  582. if (($drophigh == 1) && ($current > $highest)) { $highest = $current; }
  583. $result .= $current . '+';
  584. } while (($current == $diesize) && ($floating == 1));
  585. }
  586. $result = substr($result,0,-1);
  587. if ($droplow == 1) { $result = $result."-$lowest"; }
  588. if ($drophigh == 1) { $result = $result."-$highest"; }
  589. $result = $result.')';
  590. if ($snip == 0) {
  591. return $result;
  592. } else {
  593. return eval($result);
  594. }
  595. }
  596.  
  597. sub trim($) {
  598. my $string = shift;
  599. $string =~ s/^\s+//;
  600. $string =~ s/\s+$//;
  601. return $string;
  602. }
  603.  
  604. sub ltrim($) {
  605. my $string = shift;
  606. $string =~ s/^\s+//;
  607. return $string;
  608. }
  609.  
  610. sub rtrim($) {
  611. my $string = shift;
  612. $string =~ s/\s+$//;
  613. return $string;
  614. }
  615.  
  616. sub alltrim($) {
  617. my $string = shift;
  618. $string =~ s/\s+//g;
  619. return $string;
  620. }
  621.  
  622. sub one_shift {
  623. $shifted = shift;
  624. return $shifted;
  625. }
  626.  
  627. sub on_invite {
  628. $self = shift;
  629. $event = shift;
  630. $chan = one_shift($event->args);
  631. $self->join($chan);
  632. print STDERR "Received invite from " . $event->nick . " to ".$chan.". Joining.\n";
  633. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement