Move scramble to new hooks
This commit is contained in:
parent
d959db127f
commit
7ee6339340
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pyircbot.modulebase import ModuleBase, ModuleHook
|
from pyircbot.modulebase import ModuleBase, hook
|
||||||
|
from pyircbot.common import messageHasCommand
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -18,7 +19,6 @@ class Scramble(ModuleBase):
|
||||||
def __init__(self, bot, moduleName):
|
def __init__(self, bot, moduleName):
|
||||||
# init the base module
|
# init the base module
|
||||||
ModuleBase.__init__(self, bot, moduleName)
|
ModuleBase.__init__(self, bot, moduleName)
|
||||||
self.hooks = [ModuleHook("PRIVMSG", self.scramble)]
|
|
||||||
|
|
||||||
# Dictionary
|
# Dictionary
|
||||||
self.wordsCount = 0
|
self.wordsCount = 0
|
||||||
|
@ -40,14 +40,14 @@ class Scramble(ModuleBase):
|
||||||
# Per channel games
|
# Per channel games
|
||||||
self.games = {}
|
self.games = {}
|
||||||
# Hook in
|
# Hook in
|
||||||
self.hooks = [ModuleHook("PRIVMSG", self.scramble)]
|
|
||||||
|
|
||||||
def scramble(self, args, prefix, trailing):
|
@hook("PRIVMSG")
|
||||||
channel = args[0]
|
def scramble(self, msg, cmd):
|
||||||
|
channel = msg.args[0]
|
||||||
if channel[0] == "#":
|
if channel[0] == "#":
|
||||||
if channel not in self.games:
|
if channel not in self.games:
|
||||||
self.games[channel] = scrambleGame(self, channel)
|
self.games[channel] = scrambleGame(self, channel)
|
||||||
self.games[channel].scramble(args, prefix, trailing)
|
self.games[channel].scramble(msg.args, msg.prefix, msg.trailing)
|
||||||
|
|
||||||
def saveScores(self):
|
def saveScores(self):
|
||||||
json.dump(self.scores, open(self.scoresFile, 'w'))
|
json.dump(self.scores, open(self.scoresFile, 'w'))
|
||||||
|
@ -116,19 +116,18 @@ class scrambleGame:
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
|
|
||||||
def scramble(self, args, prefix, trailing):
|
def scramble(self, args, prefix, trailing):
|
||||||
prefix = self.master.bot.decodePrefix(prefix)
|
|
||||||
sender = prefix.nick
|
sender = prefix.nick
|
||||||
cmd = self.master.bot.messageHasCommand(".scrambleon", trailing)
|
cmd = messageHasCommand(".scrambleon", trailing)
|
||||||
if cmd and not self.running:
|
if cmd and not self.running:
|
||||||
self.running = True
|
self.running = True
|
||||||
self.startScramble()
|
self.startScramble()
|
||||||
return
|
return
|
||||||
cmd = self.master.bot.messageHasCommand(".scrambleoff", trailing)
|
cmd = messageHasCommand(".scrambleoff", trailing)
|
||||||
if cmd and self.running:
|
if cmd and self.running:
|
||||||
self.gameover()
|
self.gameover()
|
||||||
self.running = False
|
self.running = False
|
||||||
return
|
return
|
||||||
cmd = self.master.bot.messageHasCommand(".scramble top", trailing)
|
cmd = messageHasCommand(".scramble top", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
sortedscores = []
|
sortedscores = []
|
||||||
for player in self.master.scores:
|
for player in self.master.scores:
|
||||||
|
@ -144,7 +143,7 @@ class scrambleGame:
|
||||||
resp += "%s: %s, " % (sortedscores[which - 1]["name"], sortedscores[which - 1]["score"])
|
resp += "%s: %s, " % (sortedscores[which - 1]["name"], sortedscores[which - 1]["score"])
|
||||||
which += 1
|
which += 1
|
||||||
self.master.bot.act_PRIVMSG(self.channel, resp[:-2])
|
self.master.bot.act_PRIVMSG(self.channel, resp[:-2])
|
||||||
cmd = self.master.bot.messageHasCommand(".scramble score", trailing)
|
cmd = messageHasCommand(".scramble score", trailing)
|
||||||
if cmd:
|
if cmd:
|
||||||
someone = cmd.args.strip()
|
someone = cmd.args.strip()
|
||||||
if len(someone) > 0:
|
if len(someone) > 0:
|
||||||
|
|
Loading…
Reference in New Issue