mirror of
https://github.com/wr34k/IRCUFC.git
synced 2024-12-22 05:36:37 +00:00
Fixed status command + log module
This commit is contained in:
parent
2e6e55a499
commit
b021bd8ae8
16
fight.py
16
fight.py
@ -100,12 +100,16 @@ class Fight(object):
|
||||
|
||||
|
||||
def getStatus(self, nick):
|
||||
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))
|
||||
else:
|
||||
self.IRC.privmsg(nick, "Status for {} -> Current health: {} | Current stance: {}".format(f.nick, f.hp, f.stance))
|
||||
|
||||
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))
|
||||
else:
|
||||
self.IRC.privmsg(nick, "Status for {} -> Current health: {} | Current stance: {}".format(f.nick, f.hp, f.stance))
|
||||
|
||||
|
||||
def fightOver(self):
|
||||
|
78
irc.py
78
irc.py
@ -85,50 +85,62 @@ class Irc(object):
|
||||
|
||||
def listen(self):
|
||||
while True:
|
||||
if self.lag:
|
||||
self.lag=False
|
||||
data += self.sock.recv(1024).decode('utf-8', 'ignore')
|
||||
else:
|
||||
data = self.sock.recv(1024).decode('utf-8', 'ignore')
|
||||
try:
|
||||
if self.lag:
|
||||
self.lag=False
|
||||
data += self.sock.recv(1024).decode('utf-8', 'ignore')
|
||||
else:
|
||||
data = self.sock.recv(1024).decode('utf-8', 'ignore')
|
||||
|
||||
for line in [x.split() for x in data.split("\r\n") if len(x.split()) > 1]:
|
||||
self.log.info("<< {}".format(' '.join(line)))
|
||||
for line in [x.split() for x in data.split("\r\n") if len(x.split()) > 1]:
|
||||
self.log.info("<< {}".format(' '.join(line)))
|
||||
|
||||
if line[0][1:] == 'ING':
|
||||
self.raw("PONG {}".format(line[1]))
|
||||
if line[0][1:] == 'ING':
|
||||
self.raw("PONG {}".format(line[1]))
|
||||
|
||||
elif line[1] == '001': # connected
|
||||
self.join()
|
||||
elif line[1] == '001': # connected
|
||||
self.join()
|
||||
|
||||
elif line[1] == 'JOIN': # Someone joined a channel
|
||||
self.log.info("{} JOIN to {}".format(line[0], line[2]))
|
||||
pass
|
||||
elif line[1] == 'JOIN': # Someone joined a channel
|
||||
self.log.info("{} JOIN to {}".format(line[0], line[2]))
|
||||
pass
|
||||
|
||||
elif line[1] == 'PART': # Someone emopart a channel
|
||||
self.log.info("{} PART from {}".format(line[0], line[2]))
|
||||
pass
|
||||
elif line[1] == 'PART': # Someone emopart a channel
|
||||
self.log.info("{} PART from {}".format(line[0], line[2]))
|
||||
pass
|
||||
|
||||
elif line[1] == '433': # Nick already in use
|
||||
self.nick += "_"
|
||||
self.updateNick()
|
||||
elif line[1] == '433': # Nick already in use
|
||||
self.nick += "_"
|
||||
self.updateNick()
|
||||
|
||||
elif line[1] == 'KICK': #Got kicked lmao
|
||||
if line[0][1:].split("@")[0].split("!") == self.nick:
|
||||
self.log.warn("Got kicked from {} !".format(line[2]))
|
||||
chan = line[2]
|
||||
if chan == self.channel:
|
||||
elif line[1] == 'KICK': #Got kicked lmao
|
||||
if line[0][1:].split("@")[0].split("!") == self.nick:
|
||||
self.log.warn("Got kicked from {} !".format(line[2]))
|
||||
chan = line[2]
|
||||
if chan == self.channel:
|
||||
self.join()
|
||||
|
||||
elif line[1] == 'INVITE':
|
||||
self.log.info("{} invited the bot to {}".format(line[0][1:].split("!")[0], line[3][1:]))
|
||||
self.join(line[3][1:])
|
||||
elif line[1] == 'INVITE':
|
||||
self.log.info("{} invited the bot to {}".format(line[0][1:].split("!")[0], line[3][1:]))
|
||||
self.join(line[3][1:])
|
||||
|
||||
|
||||
elif line[1] == 'PRIVMSG':
|
||||
nick,user = line[0][1:].split("@")[0].split("!")
|
||||
user = user[1:] if user[0] == '~' else user
|
||||
host = line[0].split("@")[1]
|
||||
self.handle_msg(line[2], self.isAdmin(line[0][1:]), nick, user, host, ' '.join(line[3:])[1:])
|
||||
elif line[1] == 'PRIVMSG':
|
||||
nick,user = line[0][1:].split("@")[0].split("!")
|
||||
user = user[1:] if user[0] == '~' else user
|
||||
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))
|
||||
|
@ -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
4
log.py
@ -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__)
|
||||
|
Loading…
Reference in New Issue
Block a user