mirror of
https://github.com/wr34k/IRCUFC.git
synced 2024-11-25 00:46:39 +00:00
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import time
|
|
from fight import Fight
|
|
|
|
class IrcCommands(object):
|
|
def __init__(self, IRC):
|
|
self.IRC = IRC
|
|
self.fight = Fight(self.IRC)
|
|
|
|
def handle_msg(self, chan, admin, nick, user, host, msg):
|
|
args = msg.split()
|
|
if args[0][0] == self.IRC.optkey:
|
|
self.handle_cmd(chan, admin, nick, user, host, args[0][1:], args[1:])
|
|
|
|
|
|
def check_flood(self, chan, nick):
|
|
if chan not in self.IRC.flood_flag:
|
|
self.IRC.flood_flag[chan] = False
|
|
if chan not in self.IRC.last_cmd:
|
|
self.IRC.last_cmd[chan] = 0
|
|
|
|
if self.IRC.flood_flag[chan] and (time.time() - self.IRC.last_cmd[chan]) < 5:
|
|
return True
|
|
if (time.time() - self.IRC.last_cmd[chan]) < 2 and self.IRC.flood_count[chan] > 2:
|
|
self.IRC.privmsg(chan, "\00305,01{}\00315 Slow down m8".format(nick))
|
|
self.IRC.flood_flag[chan]=True
|
|
self.IRC.last_cmd[chan] = time.time()
|
|
return True
|
|
if (time.time() - self.IRC.last_cmd[chan]) < 1:
|
|
self.IRC.flood_count[chan]+=1
|
|
self.IRC.privmsg(chan, "\00305,01{}\00315 Slow down m8".format(nick))
|
|
self.IRC.last_cmd[chan] = time.time()
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def handle_cmd(self, chan, admin, nick, user, host, cmd, args):
|
|
if chan == self.IRC.nick:
|
|
chan = nick
|
|
|
|
if self.check_flood(chan, nick):
|
|
return
|
|
|
|
if admin:
|
|
if cmd == 'raw':
|
|
if args[0].lower() == 'nick':
|
|
self.IRC.nick = args[1]
|
|
self.IRC.updateNick()
|
|
elif args[0].lower() == 'join':
|
|
self.IRC.join(" ".join(args[1:]))
|
|
else:
|
|
self.IRC.raw(" ".join(args))
|
|
|
|
|
|
|
|
if self.fight.state in ('inactive', 'waiting_fighter'):
|
|
if cmd == 'fight':
|
|
self.fight.addFighter(nick)
|
|
if self.fight.state == 'fighters_ready':
|
|
self.fight.startFight()
|
|
|
|
else:
|
|
if cmd == 'status':
|
|
self.fight.getStatus(nick)
|
|
|
|
|
|
if self.fight.state == 'waiting_fighters_action':
|
|
if cmd == 'action':
|
|
if chan != self.IRC.channel:
|
|
self.fight.set_next_action(nick, args)
|
|
else:
|
|
self.IRC.privmsg(self.IRC.channel, "Not here retard your opponent can see your next move!")
|
|
|
|
|
|
self.IRC.flood_flag[chan] = False
|
|
self.IRC.flood_count[chan] = 0
|
|
self.IRC.last_cmd[chan] = time.time()
|