updated examples

pull/29/head
Mallory Hancock 2018-02-06 16:30:54 -08:00
parent 708d5146e8
commit 8adff14dbb
8 changed files with 66 additions and 22 deletions

View File

@ -0,0 +1,4 @@
import pinhook.bot
ph = pinhook.bot.Bot(['#dicechannel'], 'dicebot', 'irc.freenode.net, ops=['archangelic'])
ph.start()

View File

@ -1,4 +0,0 @@
import pinhook.bot
ph = pinhook.bot.Bot(['#arch-dev'], 'ph-bot', 'localhost', ops=['archangelic'])
ph.start()

View File

@ -0,0 +1,29 @@
import random
import re
import pinhook.plugin
dicepattern = re.compile('(?P<amount>\d+)d(?P<sides>\d+)\+?(?P<modifier>\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)

View File

@ -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))

View File

@ -0,0 +1,4 @@
import pinhook.bot
bot = pinhook.bot.TwitchBot('dicebot', '#dicechannel', 'supersecrettokenhere')
bot.start()

View File

@ -1,4 +0,0 @@
import pinhook.bot
bot = pinhook.bot.TwitchBot('ph-bot', '#example', 'supersecrettokenhere')
bot.start()

View File

@ -0,0 +1,29 @@
import random
import re
import pinhook.plugin
dicepattern = re.compile('(?P<amount>\d+)d(?P<sides>\d+)\+?(?P<modifier>\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)

View File

@ -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))