String formatting exists and it is a wonderful thing.

This commit is contained in:
dngfx 2018-09-09 03:07:21 +01:00 committed by dongfix
parent 11f7ebaa86
commit fb3fa55477

View file

@ -212,11 +212,11 @@ class Module(object):
channel.set_user_setting(uid, "ducks-befriended", total_befriended) channel.set_user_setting(uid, "ducks-befriended", total_befriended)
event["stdout"].write( msg = "Aww! %s befriended a duck! You've befriended %s ducks in %s!" \
"Aww! " + nick + " befriended a duck! You've befriended " + % ( Utils.bold(nick), Utils.bold(total_befriended),
Utils.bold( Utils.bold(channel.name) )
str(total_befriended)) + " ducks in " + Utils.bold(
channel.name) + "!") event["stdout"].write(msg)
self.clear_ducks(channel) self.clear_ducks(channel)
@ -243,10 +243,11 @@ class Module(object):
channel.set_user_setting(uid, "ducks-shot", total_shot) channel.set_user_setting(uid, "ducks-shot", total_shot)
event["stdout"].write( msg = "Pow! %s shot a duck! You've shot %s ducks in %s!" \
"Pow! " + nick + " shot a duck! You've shot " + Utils.bold( % ( Utils.bold(nick), Utils.bold(total_shot),
str(total_shot)) + " ducks in " + Utils.bold( Utils.bold(channel.name) )
channel.name) + "!")
event["stdout"].write(msg)
self.clear_ducks(channel) self.clear_ducks(channel)
@ -279,11 +280,16 @@ class Module(object):
else: else:
total_poached += number total_poached += number
event["stdout"].write( tf = total_friends
nick + ": " + str(total_poached) + " ducks killed (" + str( tp = total_poached
channel_poached) + " in " + channel + "), and " + str( cp = channel_poached
total_friends) + " ducks befriended (" + str( cf = channel_friends
channel_friends) + " in " + channel + ")")
msg = "%s ducks killed (%s in %s), and %s ducks befriended (%s in %s)" \
% ( Utils.bold(tp), Utils.bold(cp), Utils.bold(channel),
Utils.bold(tf), Utils.bold(cf), Utils.bold(channel) )
event["stdout"].write(Utils.bold(nick) + ": " + msg)
def duck_enemies(self, event): def duck_enemies(self, event):
the_enemy = event["server"].find_all_user_channel_settings("ducks-shot") the_enemy = event["server"].find_all_user_channel_settings("ducks-shot")
@ -303,14 +309,14 @@ class Module(object):
enemy_nicks.append(user) enemy_nicks.append(user)
enemy_ducks.append(enemies) enemy_ducks.append(enemies)
sentence = "Duck Wranglers -- " sentence = Utils.bold("Duck Wranglers: ")
build = [] build = []
length = len(enemy_nicks) if len(enemy_nicks) < 8 else 8 length = len(enemy_nicks) if len(enemy_nicks) < 8 else 8
for i in range(0, length): for i in range(0, length):
build.append(Utils.bold(enemy_nicks[i]) + " (" build.append("%s (%s)" % (Utils.bold(enemy_nicks[i]),
+ str(enemy_ducks[i]) + ")") enemy_ducks[i]))
sentence += ", ".join(build) sentence += ", ".join(build)
@ -335,14 +341,15 @@ class Module(object):
friend_nicks.append(user) friend_nicks.append(user)
friend_ducks.append(friends) friend_ducks.append(friends)
sentence = "Duck Befrienders -- " sentence = Utils.bold("Duck Friends: ")
length = len(friend_nicks) if len(friend_nicks) < 8 else 8 length = len(friend_nicks) if len(friend_nicks) < 8 else 8
build = [] build = []
for i in range(0, length): for i in range(0, length):
build.append(Utils.bold(friend_nicks[i]) + " (" build.append("%s (%s)" % ( Utils.bold(friend_nicks[i]),
+ str(friend_ducks[i]) + ")") friend_ducks[i])
)
sentence += ", ".join(build) sentence += ", ".join(build)