Fixed status command + log module

This commit is contained in:
wr34k 2018-06-29 14:16:26 +02:00
parent 2e6e55a499
commit b021bd8ae8
4 changed files with 60 additions and 43 deletions

View File

@ -100,6 +100,11 @@ class Fight(object):
def getStatus(self, nick):
if self.state == 'inactive':
self.IRC.privmsg(nick, "Standby, waiting for a fight to start...")
elif self.state == 'waiting_fighter':
self.IRC.privmsg(nick, "Waiting for 2nd opponent, type {}fight to register for the next fight!".format(self.IRC.optkey))
else:
for f in self.fighters:
if f.nick == nick:
self.IRC.privmsg(nick, "Status for {} -> Current health: {} | Current stance: {} | Next action: {}".format(f.nick, f.hp, f.stance, f.nextAction))
@ -107,7 +112,6 @@ class Fight(object):
self.IRC.privmsg(nick, "Status for {} -> Current health: {} | Current stance: {}".format(f.nick, f.hp, f.stance))
def fightOver(self):
winner = self.fighters[0] if self.fighters[1].hp <= 0 else self.fighters[1]
looser = self.fighters[0] if self.fighters[0].hp <= 0 else self.fighters[1]

12
irc.py
View File

@ -85,6 +85,7 @@ class Irc(object):
def listen(self):
while True:
try:
if self.lag:
self.lag=False
data += self.sock.recv(1024).decode('utf-8', 'ignore')
@ -130,6 +131,17 @@ class Irc(object):
host = line[0].split("@")[1]
self.handle_msg(line[2], self.isAdmin(line[0][1:]), nick, user, host, ' '.join(line[3:])[1:])
except (UnicodeDecodeError, UnicodeEncodeError):
pass
except KeyboardInterrupt:
self.log.warn("^C, Exiting...")
return
except Exception as e:
self.log.error("Exception in listen()", e)
pass
def join(self):
self.log.info("Now joining {} ...".format(self.channel))
self.raw("JOIN {} {}".format(self.channel, self.chankey)) if self.chankey else self.raw("JOIN {}".format(self.channel))

View File

@ -55,6 +55,8 @@ class IrcCommands(object):
self.IRC.raw(" ".join(args))
if cmd == 'status':
self.fight.getStatus(chan)
if self.fight.state in ('inactive', 'waiting_fighter'):
if cmd == 'fight':
@ -69,9 +71,6 @@ class IrcCommands(object):
else:
self.IRC.privmsg(self.IRC.channel, "{}".format(self.IRC.mirc.color("Not here retard your opponent can see your next move!", self.IRC.mirc.colors.LIGHTRED)))
else:
if cmd == 'status':
self.fight.getStatus(chan)
self.IRC.flood_flag[chan] = False
self.IRC.flood_count[chan] = 0

4
log.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
import traceback
class Colors(object):
class Format(object):
@ -60,7 +61,7 @@ class Log(object):
self.func = func
def construct(self, *args):
return "".join(a for a in args)
return "".join(args)
def info(self, msg):
if self.debug:
@ -75,3 +76,4 @@ class Log(object):
self.func( self.construct( "[", self.colors.fg.LIGHTRED, "x", self.colors.fg.DEFAULT, "] ", msg ) )
if exception:
self.func( self.construct( "[", self.colors.fg.LIGHTRED, "x", self.colors.fg.DEFAULT, "] ", str(exception) ) )
traceback.print_tb(exception.__traceback__)