Awesome IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2 KiB

#!/usr/bin/env python
.. module:: GameBase
:synopsis: A codebase for making IRC games
.. moduleauthor:: Dave Pedu <>
from pyircbot.modulebase import ModuleBase, ModuleHook
class GameBase(ModuleBase):
def __init__(self, bot, moduleName):
ModuleBase.__init__(self, bot, moduleName)
self.hooks = [ModuleHook("PRIVMSG", self.gotMsg)]
# Load attribute storage
self.attr ="attributes")
# Load doge RPC
self.doge ="dogerpc")
# Dict of #channel -> game object = {}
def gotMsg(self, args, prefix, trailing):
prefixObj =
# Ignore messages from users not logged in
if not self.attr.getKey(prefixObj.nick, "loggedinfrom"):
# TODO Send them a hint?
if args[0][0] == "#":
# create a blank game obj if there isn't one (and whitelisted ? )
if not args[0] in and (not self.config["channelWhitelistOn"] or
(self.config["channelWhitelistOn"] and args[0][1:] in self.config["channelWhitelist"])):[args[0]] = gameObj(self, args[0])
# Channel message[args[0]].gotMsg(args, prefix, trailing)
# Private message
#[args[0]].gotPrivMsg(args, prefix, trailing)
def ondisable(self):"GameBase: Unload requested, ending games...")
for game in[game].gameover()
class gameObj:
def __init__(self, master, channel):
self.master = master = channel
def gotPrivMsg(self, args, prefix, trailing):
prefix =
def gotMsg(self, args, prefix, trailing):
prefix =
# senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes"
def gameover(self):
class playerObj:
def __init__(self, game, nick): = game
self.nick = nick