pyircbot/pyircbot/modules/GameBase.py

71 lines
2.2 KiB
Python
Raw Normal View History

2013-12-28 09:58:20 -08:00
#!/usr/bin/env python
2014-10-02 18:14:42 -07:00
"""
.. module:: GameBase
2015-11-01 18:03:11 -08:00
:synopsis: A codebase for making IRC games
2014-10-02 18:14:42 -07:00
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
"""
2017-01-01 14:59:01 -08:00
from pyircbot.modulebase import ModuleBase, ModuleHook
2013-12-28 09:58:20 -08:00
class GameBase(ModuleBase):
2015-11-01 18:03:11 -08:00
def __init__(self, bot, moduleName):
2017-01-01 14:59:01 -08:00
ModuleBase.__init__(self, bot, moduleName)
self.hooks = [ModuleHook("PRIVMSG", self.gotMsg)]
2015-11-01 18:03:11 -08:00
# Load attribute storage
self.attr = self.bot.getBestModuleForService("attributes")
# Load doge RPC
self.doge = self.bot.getBestModuleForService("dogerpc")
# Dict of #channel -> game object
self.games = {}
2017-01-01 14:59:01 -08:00
2015-11-01 18:03:11 -08:00
def gotMsg(self, args, prefix, trailing):
prefixObj = self.bot.decodePrefix(prefix)
# Ignore messages from users not logged in
2017-01-01 14:59:01 -08:00
if not self.attr.getKey(prefixObj.nick, "loggedinfrom"):
# TODO Send them a hint?
2015-11-01 18:03:11 -08:00
return
else:
if args[0][0] == "#":
# create a blank game obj if there isn't one (and whitelisted ? )
2017-01-01 14:59:01 -08:00
if not args[0] in self.games and (not self.config["channelWhitelistOn"] or
(self.config["channelWhitelistOn"] and args[0][1:] in self.config["channelWhitelist"])):
self.games[args[0]] = gameObj(self, args[0])
2015-11-01 18:03:11 -08:00
# Channel message
self.games[args[0]].gotMsg(args, prefix, trailing)
else:
# Private message
2017-01-01 14:59:01 -08:00
# self.games[args[0]].gotPrivMsg(args, prefix, trailing)
2015-11-01 18:03:11 -08:00
pass
2017-01-01 14:59:01 -08:00
2015-11-01 18:03:11 -08:00
def ondisable(self):
self.log.info("GameBase: Unload requested, ending games...")
for game in self.games:
self.games[game].gameover()
2013-12-28 09:58:20 -08:00
2017-01-01 14:59:01 -08:00
2013-12-28 09:58:20 -08:00
class gameObj:
2015-11-01 18:03:11 -08:00
def __init__(self, master, channel):
self.master = master
self.channel = channel
2017-01-01 14:59:01 -08:00
2015-11-01 18:03:11 -08:00
def gotPrivMsg(self, args, prefix, trailing):
prefix = self.master.bot.decodePrefix(prefix)
pass
2017-01-01 14:59:01 -08:00
2015-11-01 18:03:11 -08:00
def gotMsg(self, args, prefix, trailing):
prefix = self.master.bot.decodePrefix(prefix)
pass
2017-01-01 14:59:01 -08:00
# senderIsOp = self.master.attr.getKey(prefix.nick, "op")=="yes"
2015-11-01 18:03:11 -08:00
def gameover(self):
pass
2013-12-28 09:58:20 -08:00
2017-01-01 14:59:01 -08:00
2013-12-28 09:58:20 -08:00
class playerObj:
2015-11-01 18:03:11 -08:00
def __init__(self, game, nick):
self.game = game
self.nick = nick