Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function nassau_dice_filter($o) {
- $preg = '/\[dice=(?<num>\d*)[kd](?<dice>\d+)\]((?<res>[^\[]*)\[\/dice\])?/i';
- $o->Msg = preg_replace_callback($preg, 'nassau_dice_parse', $o->Msg);
- }
- function nassau_dice_parse($m) {
- if (false == empty($m['res'])) return $m[0];
- $dice = $m['dice'];
- $num = $m['num'] ? $m['num'] : 1;
- $sum = array ();
- foreach (range(1, $num) as $_) $sum[] = rand(1, $dice);
- $sum = implode(', ', $sum) . ' » ' . array_sum($sum);
- return sprintf('[dice=%dd%d]%s[/dice]', $num, $dice, $sum);
- }
- function nassau_dice_format(&$data) {
- $msg = $data['message'];
- $rep = preg_replace('/\[dice=(\d*[kd]\d+)\]([^\[]+)\[\/dice\]/i',
- '<span style="background:#0080FF;color:white;padding:1px 4px;border-radius:6px;">Rolled [$1]: $2</span>',
- $msg);
- $data['message'] = $rep;
- }
- UnbRegisterHook('post.beforeadd', 'nassau_dice_filter');
- UnbRegisterHook('post.beforechange', 'nassau_dice_filter');
- UnbRegisterHook('post.postparse', 'nassau_dice_format');
Add Comment
Please, Sign In to add comment