Skip to content

Instantly share code, notes, and snippets.

@Karunamon
Created December 26, 2015 17:24
Show Gist options
  • Save Karunamon/915735cc515d78c090a4 to your computer and use it in GitHub Desktop.
Save Karunamon/915735cc515d78c090a4 to your computer and use it in GitHub Desktop.
irc3 python bot shenanigans
[bot]
nick = AsrielBot
realname = Dreemurr
host = irc.rizon.net
port = 6697
ssl = true
ssl_verify = CERT_NONE
includes =
irc3.plugins.command
plugins.dice
autojoins =
tkware
[irc3.plugins.command]
cmd = ?
guard = irc3.plugins.command.mask_based_policy
[irc3.plugins.command.masks]
Necoco!*@*.* = all_permissions
# -*- coding: utf-8 -*-
from irc3.plugins.command import command
from irc3.dec import event
import irc3
import random
import re
def handle_shadowrun(arg):
"""
:type arg: list
:returns: string
"""
glitches = 0
successes = 0
critical_threshold = len(arg)/2
result = ""
for n in arg:
if n == 1:
glitches += 1
elif n == 5 or n == 6:
successes += 1
if glitches >= critical_threshold:
result = "(CRITICAL FAILURE!)"
elif glitches >= successes:
result = "(Failure!)"
elif successes > glitches:
result = "(Successful!)"
else:
result = "(No success, no glitch)"
return result
@irc3.plugin
class Dice(object):
def __init__(self, bot):
self.bot = bot
self.rng = random.SystemRandom()
self.debug_mode = True
@command
def roll(self, mask, target, args):
"""
Rolls dice. "<dice>" Can be understood as d notation like 2d20 or 1d6.
Usage:
%%roll <dice>
%%roll <dice> [<description_text>...]
%%roll <dice> [-s] [<description_text>...]
Options:
-s, --shadowrun Outputs dice in Shadowrun action format.
"""
d = args['<dice>'].split("d")
count = int(d[0])
sides = int(d[1])
if sides > 100:
self.bot.privmsg(target, "That's an absurd number of sides.")
return True
if count > 100:
self.bot.privmsg(target, "That's too many dice!")
return True
dice = []
result = ""
for n in range(0, count):
dice.append(self.rng.randint(1, sides))
if args["<description_text>"]:
result += (" %s" % ' '.join(args["<description_text>"]))
if args["-s"]:
result += (" %s" % handle_shadowrun(dice))
self.bot.privmsg(target, str(dice) + result)
# This does not work since @event doesn't get evaluated in the same way @command does :(
# @event("^:(?P<mask>\S+!\S+@\S+) (PRIVMSG) (?P<target>\S+) :\s*(?P<args>\S+.*)$")
# def easy_roll(self):
# return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment