From 8adff14dbb4136ccbe18917b0ac15247c3803c45 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Tue, 6 Feb 2018 16:30:54 -0800 Subject: [PATCH] updated examples --- examples/irc/dicebot.py | 4 ++++ examples/irc/ph.py | 4 ---- examples/irc/plugins/dice.py | 29 +++++++++++++++++++++++++++++ examples/irc/plugins/test.py | 7 ------- examples/twitch/dicebot.py | 4 ++++ examples/twitch/ph.py | 4 ---- examples/twitch/plugins/dice.py | 29 +++++++++++++++++++++++++++++ examples/twitch/plugins/test.py | 7 ------- 8 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 examples/irc/dicebot.py delete mode 100644 examples/irc/ph.py create mode 100644 examples/irc/plugins/dice.py delete mode 100644 examples/irc/plugins/test.py create mode 100644 examples/twitch/dicebot.py delete mode 100644 examples/twitch/ph.py create mode 100644 examples/twitch/plugins/dice.py delete mode 100644 examples/twitch/plugins/test.py diff --git a/examples/irc/dicebot.py b/examples/irc/dicebot.py new file mode 100644 index 0000000..ea16c62 --- /dev/null +++ b/examples/irc/dicebot.py @@ -0,0 +1,4 @@ +import pinhook.bot + +ph = pinhook.bot.Bot(['#dicechannel'], 'dicebot', 'irc.freenode.net, ops=['archangelic']) +ph.start() diff --git a/examples/irc/ph.py b/examples/irc/ph.py deleted file mode 100644 index acf7d01..0000000 --- a/examples/irc/ph.py +++ /dev/null @@ -1,4 +0,0 @@ -import pinhook.bot - -ph = pinhook.bot.Bot(['#arch-dev'], 'ph-bot', 'localhost', ops=['archangelic']) -ph.start() diff --git a/examples/irc/plugins/dice.py b/examples/irc/plugins/dice.py new file mode 100644 index 0000000..a79127a --- /dev/null +++ b/examples/irc/plugins/dice.py @@ -0,0 +1,29 @@ +import random +import re + +import pinhook.plugin + +dicepattern = re.compile('(?P\d+)d(?P\d+)\+?(?P\d+)?') + +def build_output(rolls, modifier): + if len(rolls) == 1: + start = str(sum(rolls)) + else: + all_rolls = ''.join([str(i)+', ' for i in rolls]).strip(', ') + start = '{} = {}'.format(all_rolls, sum(rolls)) + if modifier: + output = start + ' + {} = '.format(modifier) + else: + output = start + return output + +@pinhook.plugin.register('!roll') +def roll(msg): + matches = dicepatern.match(msg.arg) + if matches: + msg.logger.info('Valid dice roll: {}'.format(msg.arg)) + rolls = [random.randrange(1, int(matches.group('sides'))+1) for i in range(int(matches.group('amount')))] + output = build_output(rolls, matches.group('modifier')) + else: + output = '{}: improper format, should be NdN+N'.format(msg.nick) + return pinhook.plugin.message(output) diff --git a/examples/irc/plugins/test.py b/examples/irc/plugins/test.py deleted file mode 100644 index 22908a6..0000000 --- a/examples/irc/plugins/test.py +++ /dev/null @@ -1,7 +0,0 @@ -import pinhook.plugin - -@pinhook.plugin.register('!test') -def test(msg): - msg.logger.info('This is test log output') - return pinhook.plugin.message("{}: Test".format(msg.nick)) - diff --git a/examples/twitch/dicebot.py b/examples/twitch/dicebot.py new file mode 100644 index 0000000..eeb0a11 --- /dev/null +++ b/examples/twitch/dicebot.py @@ -0,0 +1,4 @@ +import pinhook.bot + +bot = pinhook.bot.TwitchBot('dicebot', '#dicechannel', 'supersecrettokenhere') +bot.start() \ No newline at end of file diff --git a/examples/twitch/ph.py b/examples/twitch/ph.py deleted file mode 100644 index 5b40fd2..0000000 --- a/examples/twitch/ph.py +++ /dev/null @@ -1,4 +0,0 @@ -import pinhook.bot - -bot = pinhook.bot.TwitchBot('ph-bot', '#example', 'supersecrettokenhere') -bot.start() \ No newline at end of file diff --git a/examples/twitch/plugins/dice.py b/examples/twitch/plugins/dice.py new file mode 100644 index 0000000..a79127a --- /dev/null +++ b/examples/twitch/plugins/dice.py @@ -0,0 +1,29 @@ +import random +import re + +import pinhook.plugin + +dicepattern = re.compile('(?P\d+)d(?P\d+)\+?(?P\d+)?') + +def build_output(rolls, modifier): + if len(rolls) == 1: + start = str(sum(rolls)) + else: + all_rolls = ''.join([str(i)+', ' for i in rolls]).strip(', ') + start = '{} = {}'.format(all_rolls, sum(rolls)) + if modifier: + output = start + ' + {} = '.format(modifier) + else: + output = start + return output + +@pinhook.plugin.register('!roll') +def roll(msg): + matches = dicepatern.match(msg.arg) + if matches: + msg.logger.info('Valid dice roll: {}'.format(msg.arg)) + rolls = [random.randrange(1, int(matches.group('sides'))+1) for i in range(int(matches.group('amount')))] + output = build_output(rolls, matches.group('modifier')) + else: + output = '{}: improper format, should be NdN+N'.format(msg.nick) + return pinhook.plugin.message(output) diff --git a/examples/twitch/plugins/test.py b/examples/twitch/plugins/test.py deleted file mode 100644 index 22908a6..0000000 --- a/examples/twitch/plugins/test.py +++ /dev/null @@ -1,7 +0,0 @@ -import pinhook.plugin - -@pinhook.plugin.register('!test') -def test(msg): - msg.logger.info('This is test log output') - return pinhook.plugin.message("{}: Test".format(msg.nick)) -