Fixing IRC colors

This commit is contained in:
wr34k 2018-06-28 12:24:40 +02:00
parent 3329b113f4
commit 69c7df50ec
4 changed files with 41 additions and 32 deletions

View File

@ -35,8 +35,8 @@ class Fight(object):
def startFight(self): def startFight(self):
self.state = 'starting_fight' self.state = 'starting_fight'
self.fighters[0] = Fighter(self.fighters[0], self.IRC.mirc.RED) self.fighters[0] = Fighter(self.fighters[0], self.IRC.mirc.colors.RED)
self.fighters[1] = Fighter(self.fighters[1], self.IRC.mirc.BLUE) self.fighters[1] = Fighter(self.fighters[1], self.IRC.mirc.colors.BLUE)
# who start? # who start?

18
irc.py
View File

@ -11,12 +11,12 @@ from ircCommands import IrcCommands
server = 'irc.servercentral.net' server = 'irc.servercentral.net'
port = 9999 port = 9999
channel = ('#wololo', None) # (chan, key) channel = ('#IRCUFC', None) # (chan, key)
use_ssl = True use_ssl = True
nickname = 'devbruce' nickname = 'IRCUFC'
username = 'rrarrar' username = 'McBuffer'
realname = '** WE BOTTIN **' realname = '** WE FIGHTIN **'
optkey= "!" optkey= "!"
timeout=0.4 timeout=0.4
@ -25,8 +25,6 @@ DEBUG = True
sys.dont_write_bytecode = True sys.dont_write_bytecode = True
class Irc(object): class Irc(object):
def __init__(self): def __init__(self):
@ -159,10 +157,10 @@ class Irc(object):
if args[0] == '{}reload'.format(self.optkey): if args[0] == '{}reload'.format(self.optkey):
ret = recompile(args[1]) # Let you add new code to the bot without restarting it ret = recompile(args[1]) # Let you add new code to the bot without restarting it
if ret == True: if ret == True:
self.privmsg(chan, "{} recompiled successfully!".format(args[1])) self.privmsg(chan, "{} recompiled successfully!".format(self.mirc.color(args[1], self.mirc.colors.GREEN)))
return return
else: else:
self.privmsg(chan, "Man we had a issue while recompiling {}".format(args[1])) self.privmsg(chan, "Man we had a issue while recompiling {}".format(self.mirc.color(args[1], self.mirc.colors.GREEN)))
self.log.error(ret) self.log.error(ret)
return return
@ -173,11 +171,11 @@ class Irc(object):
if chan not in self.timeouts: if chan not in self.timeouts:
self.timeouts[chan] = {'last_cmd': time.time(), 'burst': 0, 'timeout': 0} self.timeouts[chan] = {'last_cmd': time.time(), 'burst': 0, 'timeout': 0}
self.raw("PRIVMSG {} :{}".format(chan, msg), self.timeouts[chan]['timeout']) self.raw("PRIVMSG {} :{}".format(chan, msg), self.timeouts[chan]['timeout'])
self.editTimeouts() self.editTimeouts(chan)
def editTimeouts(self): def editTimeouts(self, chan):
if (time.time() - self.timeouts[chan]['last_cmd']) < 3: if (time.time() - self.timeouts[chan]['last_cmd']) < 3:
self.timeouts[chan]['burst'] += 1 self.timeouts[chan]['burst'] += 1
else: else:

View File

@ -23,13 +23,13 @@ class IrcCommands(object):
if self.IRC.flood_flag[chan] and (time.time() - self.IRC.last_cmd[chan]) < 5: if self.IRC.flood_flag[chan] and (time.time() - self.IRC.last_cmd[chan]) < 5:
return True return True
if (time.time() - self.IRC.last_cmd[chan]) < 2 and self.IRC.flood_count[chan] > 2: 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.privmsg(chan, "{} Slow down m8".format(self.IRC.mirc.color(nick, self.IRC.mirc.colors.RED) ))
self.IRC.flood_flag[chan]=True self.IRC.flood_flag[chan]=True
self.IRC.last_cmd[chan] = time.time() self.IRC.last_cmd[chan] = time.time()
return True return True
if (time.time() - self.IRC.last_cmd[chan]) < 1: if (time.time() - self.IRC.last_cmd[chan]) < 1:
self.IRC.flood_count[chan]+=1 self.IRC.flood_count[chan]+=1
self.IRC.privmsg(chan, "\00305,01{}\00315 Slow down m8".format(nick)) self.IRC.privmsg(chan, "{} Slow down m8".format(self.IRC.mirc.color(nick, self.IRC.mirc.colors.RED) ))
self.IRC.last_cmd[chan] = time.time() self.IRC.last_cmd[chan] = time.time()
return True return True
@ -64,7 +64,7 @@ class IrcCommands(object):
else: else:
if cmd == 'status': if cmd == 'status':
self.fight.getStatus(nick) self.fight.getStatus(chan)
if self.fight.state == 'waiting_fighters_action': if self.fight.state == 'waiting_fighters_action':
@ -72,7 +72,7 @@ class IrcCommands(object):
if chan != self.IRC.channel: if chan != self.IRC.channel:
self.fight.set_next_action(nick, args) self.fight.set_next_action(nick, args)
else: else:
self.IRC.privmsg(self.IRC.channel, "Not here retard your opponent can see your next move!") 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)))
self.IRC.flood_flag[chan] = False self.IRC.flood_flag[chan] = False

View File

@ -6,19 +6,30 @@ class MIRCFormat(object):
UNDERLINED = "\x1F" UNDERLINED = "\x1F"
REVERSE = "\x16" REVERSE = "\x16"
RESET = "\x0F" RESET = "\x0F"
WHITE = "\x0300"
BLACK = "\x0301" class Colors():
BLUE = "\x0302" WHITE = "00"
GREEN = "\x0303" BLACK = "01"
RED = "\x0304" BLUE = "02"
BROWN = "\x0305" GREEN = "03"
PURPLE = "\x0306" RED = "04"
ORANGE = "\x0307" BROWN = "05"
YELLOW = "\x0308" PURPLE = "06"
LIGHTGREEN = "\x0309" ORANGE = "07"
CYAN = "\x0310" YELLOW = "08"
LIGHTCYAN = "\x0311" LIGHTGREEN = "09"
LIGHTBLUE = "\x0312" CYAN = "10"
PINK = "\x0313" LIGHTCYAN = "11"
GREY = "\x0314" LIGHTBLUE = "12"
LIGHTGREY = "\x0315" PINK = "13"
GREY = "14"
LIGHTGREY = "15"
def __init__(self):
self.colors = self.Colors()
def color(self, msg, fg, bg=None):
if bg:
return "\x03{},{}{}{}".format(fg,bg,msg,self.RESET)
else:
return "\x03{}{}{}".format(fg, msg, self.RESET)