2018-09-08 15:15:43 +00:00
|
|
|
import random
|
2018-08-31 15:58:25 +00:00
|
|
|
from operator import itemgetter
|
2018-09-08 15:15:43 +00:00
|
|
|
from time import time
|
2018-09-24 14:13:27 +00:00
|
|
|
from src import EventManager, Utils
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
DUCK_TAIL = "・゜゜・。。・゜゜"
|
|
|
|
DUCK_HEAD = ["\_o< ", "\_O< ", "\_0< ", "\_\u00f6< ", "\_\u00f8< ",
|
|
|
|
"\_\u00f3< "]
|
|
|
|
DUCK_MESSAGE = ["QUACK!", "FLAP FLAP!", "quack!", "squawk!"]
|
2018-09-08 18:10:09 +00:00
|
|
|
DUCK_MESSAGE_RARE = ["beep boop!", "QUACK QUACK QUACK QUACK QUACK!!", "HONK!",
|
2018-09-08 18:11:12 +00:00
|
|
|
Utils.underline("I AM THE METAL DUCK")]
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
DUCK_MINIMUM_MESSAGES = 10
|
|
|
|
DUCK_MINIMUM_UNIQUE = 3
|
|
|
|
|
2018-09-09 07:59:36 +00:00
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-08-31 03:14:56 +00:00
|
|
|
self.bot = bot
|
2018-09-19 12:23:18 +00:00
|
|
|
exports.add("channelset", {"setting": "ducks-enabled",
|
|
|
|
"help": "Toggle ducks!", "validate": Utils.bool_or_none})
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
exports.add("channelset", {"setting": "ducks-kick",
|
2018-09-19 12:23:18 +00:00
|
|
|
"help": "Should the bot kick if there's no duck?",
|
|
|
|
"validate": Utils.bool_or_none})
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-22 15:02:39 +00:00
|
|
|
exports.add("channelset", {"setting": "ducks-min-unique",
|
2018-09-26 17:27:17 +00:00
|
|
|
"help": "Minimum unique users required to talk before a "
|
|
|
|
"duck spawns.", "validate": Utils.int_or_none})
|
2018-09-22 15:02:39 +00:00
|
|
|
|
|
|
|
exports.add("channelset", {"setting": "ducks-min-messages",
|
2018-09-26 17:27:17 +00:00
|
|
|
"help": "Minimum messages between ducks spawning.",
|
|
|
|
"validate": Utils.int_or_none})
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 21:01:47 +00:00
|
|
|
for server in self.bot.servers.values():
|
2018-09-08 20:58:32 +00:00
|
|
|
for channel in server.channels.values():
|
|
|
|
self.bootstrap(channel)
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("new.channel")
|
2018-09-08 21:01:47 +00:00
|
|
|
def new_channel(self, event):
|
|
|
|
self.bootstrap(event["channel"])
|
2018-09-09 07:59:36 +00:00
|
|
|
|
2018-09-08 21:01:47 +00:00
|
|
|
def bootstrap(self, channel):
|
2018-09-08 15:15:43 +00:00
|
|
|
self.init_game_var(channel)
|
|
|
|
# getset
|
|
|
|
ducks_enabled = channel.get_setting("ducks-enabled", False)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
if ducks_enabled == True:
|
|
|
|
self.start_game(channel)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def is_duck_channel(self, channel):
|
|
|
|
if channel.get_setting("ducks-enabled", False) == False:
|
|
|
|
return False
|
2018-09-01 00:56:07 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
if hasattr(channel, 'games') == False:
|
|
|
|
return False
|
2018-09-01 11:24:00 +00:00
|
|
|
|
2018-09-08 16:02:03 +00:00
|
|
|
if "ducks" not in channel.games.keys():
|
2018-09-08 15:15:43 +00:00
|
|
|
return False
|
2018-09-01 00:56:07 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
return True
|
2018-08-31 04:48:53 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def init_game_var(self, channel):
|
|
|
|
if hasattr(channel, 'games') == False:
|
|
|
|
channel.games = {}
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def clear_ducks(self, channel):
|
|
|
|
rand_time = self.generate_next_duck_time()
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-22 19:08:07 +00:00
|
|
|
if hasattr(channel.games, "ducks"):
|
|
|
|
del channel.games["ducks"]
|
|
|
|
|
2018-09-08 18:10:09 +00:00
|
|
|
channel.games["ducks"] = {'messages': 0, 'duck_spawned': 0,
|
|
|
|
'unique_users': [],
|
2018-09-22 15:02:39 +00:00
|
|
|
'next_duck_time': rand_time,
|
|
|
|
'decoy_spawned': 0, 'decoy_requested': 0,
|
|
|
|
'next_decoy_time': rand_time}
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def start_game(self, channel):
|
|
|
|
# event is immediately the IRCChannel.Channel() event for the current
|
|
|
|
# channel
|
|
|
|
self.clear_ducks(channel)
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-22 18:32:54 +00:00
|
|
|
min_unique = channel.get_setting("ducks-min-unique", 0)
|
|
|
|
min_messages = channel.get_setting("ducks-min-messages", 0)
|
2018-09-22 15:02:39 +00:00
|
|
|
|
|
|
|
if min_unique == 0:
|
|
|
|
channel.set_setting("ducks-min-unique", DUCK_MINIMUM_UNIQUE)
|
|
|
|
|
|
|
|
if min_messages == 0:
|
|
|
|
channel.set_setting("ducks-min-messages", DUCK_MINIMUM_MESSAGES)
|
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def generate_next_duck_time(self):
|
2018-09-22 18:32:54 +00:00
|
|
|
rand_time = random.randint(int(time()) + 360, int(time()) + 1200)
|
2018-09-08 15:15:43 +00:00
|
|
|
return rand_time
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-22 18:10:52 +00:00
|
|
|
def is_duck_visible(self, event, decoy=False):
|
2018-09-08 15:15:43 +00:00
|
|
|
channel = event["target"]
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-22 18:10:52 +00:00
|
|
|
visible = channel.games["ducks"]["decoy_spawned"] if \
|
|
|
|
decoy else channel.games["ducks"]["duck_spawned"]
|
2018-09-08 15:15:43 +00:00
|
|
|
return visible
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def should_kick(self, event):
|
|
|
|
channel = event["target"]
|
2018-09-22 15:02:39 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
return channel.get_setting("ducks-kick", False)
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def kick_bef(self, event):
|
|
|
|
channel = event["target"]
|
|
|
|
target = event["user"].nickname
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.send_kick(target,
|
|
|
|
"You tried befriending a non-existent duck. Creepy!")
|
2018-08-31 17:23:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def kick_bang(self, event):
|
|
|
|
channel = event["target"]
|
|
|
|
target = event["user"].nickname
|
2018-08-31 15:06:11 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.send_kick(target,
|
|
|
|
"You tried shooting a non-existent duck. Creepy!")
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.decoy")
|
2018-09-22 15:02:39 +00:00
|
|
|
def duck_decoy(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Prepare a decoy duck
|
|
|
|
"""
|
2018-09-22 15:02:39 +00:00
|
|
|
channel = event["target"]
|
|
|
|
if self.is_duck_channel(channel) == False:
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.is_duck_visible(event):
|
|
|
|
return
|
|
|
|
|
|
|
|
game = channel.games["ducks"]
|
|
|
|
game["decoy_requested"] = 1
|
|
|
|
|
|
|
|
event.eat()
|
|
|
|
|
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def should_generate_duck(self, event):
|
|
|
|
channel = event["channel"]
|
|
|
|
game = channel.games["ducks"]
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-22 15:02:39 +00:00
|
|
|
spawned = int(game["decoy_spawned"] or game["duck_spawned"])
|
|
|
|
decoy = bool(game["decoy_requested"])
|
2018-09-08 15:15:43 +00:00
|
|
|
unique = len(game["unique_users"])
|
|
|
|
messages = game["messages"]
|
2018-09-22 15:02:39 +00:00
|
|
|
next_duck = game["next_decoy_time"] if decoy else game["next_duck_time"]
|
|
|
|
|
|
|
|
min_unique = 1 if decoy else channel.get_setting("ducks-min-unique",
|
|
|
|
DUCK_MINIMUM_UNIQUE)
|
|
|
|
min_messages = channel.get_setting("ducks-min-messages", DUCK_MINIMUM_MESSAGES)
|
|
|
|
|
|
|
|
requirement = (unique >= min_unique and messages >= min_messages)
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
# DUCK_MINIMUM_MESSAGES = 10
|
|
|
|
# DUCK_MINIMUM_UNIQUE = 3
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-22 15:02:39 +00:00
|
|
|
if spawned == 0 and next_duck < time():
|
|
|
|
if requirement:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2018-09-08 15:15:43 +00:00
|
|
|
else:
|
|
|
|
return False
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
def show_duck(self, event):
|
|
|
|
channel = event["channel"]
|
2018-09-22 15:02:39 +00:00
|
|
|
game = channel.games["ducks"]
|
2018-09-08 15:15:43 +00:00
|
|
|
duck = ""
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-22 15:02:39 +00:00
|
|
|
if game["duck_spawned"] == 1 or game["decoy_spawned"] == 1:
|
2018-09-08 15:15:43 +00:00
|
|
|
return
|
2018-08-31 15:58:25 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
duck += DUCK_TAIL
|
|
|
|
duck += random.choice(DUCK_HEAD)
|
|
|
|
|
2018-09-21 10:38:55 +00:00
|
|
|
if random.randint(1, 20) == 1:
|
|
|
|
# rare!
|
|
|
|
message = random.choice(DUCK_MESSAGE_RARE)
|
|
|
|
duck = Utils.color(Utils.bold(duck + message), Utils.COLOR_RED)
|
|
|
|
else:
|
|
|
|
# not rare!
|
|
|
|
duck += random.choice(DUCK_MESSAGE)
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
channel.send_message(duck)
|
2018-09-22 15:02:39 +00:00
|
|
|
|
|
|
|
# Decoys take priority over regular ducks.
|
|
|
|
if game["decoy_requested"] == 1:
|
|
|
|
game["decoy_spawned"] = 1
|
|
|
|
game["decoy_requested"] = 0
|
|
|
|
|
|
|
|
game["next_duck_time"] = self.generate_next_duck_time()
|
|
|
|
else:
|
|
|
|
game["duck_spawned"] = 1
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.message.channel",
|
|
|
|
priority=EventManager.PRIORITY_MONITOR)
|
2018-09-08 15:15:43 +00:00
|
|
|
def channel_message(self, event):
|
2018-09-19 13:25:33 +00:00
|
|
|
if not event["channel"].get_setting("ducks-enabled", False):
|
|
|
|
return
|
2018-09-08 15:15:43 +00:00
|
|
|
channel = event["channel"]
|
|
|
|
|
|
|
|
if "ducks" not in channel.games.keys():
|
|
|
|
return
|
2018-08-31 05:27:41 +00:00
|
|
|
|
2018-08-31 13:36:25 +00:00
|
|
|
user = event["user"]
|
2018-09-08 15:15:43 +00:00
|
|
|
game = channel.games["ducks"]
|
2018-08-31 13:36:25 +00:00
|
|
|
|
2018-09-22 15:02:39 +00:00
|
|
|
if game["decoy_spawned"] == 1 or game["duck_spawned"] == 1 or \
|
|
|
|
channel.has_user(event["user"]) == False:
|
2018-09-08 15:15:43 +00:00
|
|
|
return
|
2018-08-31 04:48:53 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
unique = game["unique_users"]
|
|
|
|
messages = game["messages"]
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
if user not in unique:
|
|
|
|
game["unique_users"].append(user)
|
|
|
|
messages_increment = 1
|
|
|
|
else:
|
|
|
|
messages_increment = 0.5
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
game["messages"] = messages + messages_increment
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
if self.should_generate_duck(event) == True:
|
|
|
|
self.show_duck(event)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.bef")
|
2018-09-08 15:15:43 +00:00
|
|
|
def befriend(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Befriend a duck
|
|
|
|
"""
|
2018-09-08 15:15:43 +00:00
|
|
|
channel = event["target"]
|
2018-08-31 13:36:25 +00:00
|
|
|
user = event["user"]
|
2018-09-08 15:15:43 +00:00
|
|
|
nick = user.nickname
|
|
|
|
uid = user.get_id()
|
|
|
|
if self.is_duck_channel(channel) == False:
|
|
|
|
return
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-22 18:10:52 +00:00
|
|
|
if self.is_duck_visible(event, False) == False:
|
2018-09-08 15:15:43 +00:00
|
|
|
if self.should_kick(event):
|
|
|
|
self.kick_bef(event)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-09-22 18:10:52 +00:00
|
|
|
|
|
|
|
self.clear_ducks(channel)
|
2018-09-08 15:15:43 +00:00
|
|
|
return
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.games["ducks"][
|
|
|
|
"next_duck_time"] = self.generate_next_duck_time()
|
|
|
|
channel.games["ducks"]["duck_spawned"] = 0
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
total_befriended = channel.get_user_setting(uid, "ducks-befriended", 0)
|
|
|
|
total_befriended = total_befriended + 1
|
2018-09-01 00:56:07 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.set_user_setting(uid, "ducks-befriended", total_befriended)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-09 02:07:21 +00:00
|
|
|
msg = "Aww! %s befriended a duck! You've befriended %s ducks in %s!" \
|
2018-09-09 07:59:36 +00:00
|
|
|
% (Utils.bold(nick), Utils.bold(total_befriended),
|
|
|
|
Utils.bold(channel.name))
|
2018-09-09 02:07:21 +00:00
|
|
|
|
|
|
|
event["stdout"].write(msg)
|
2018-09-01 17:45:01 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
self.clear_ducks(channel)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-08-31 03:35:42 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.bang")
|
2018-09-08 15:15:43 +00:00
|
|
|
def shoot(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Shoot a duck
|
|
|
|
"""
|
2018-09-08 15:15:43 +00:00
|
|
|
channel = event["target"]
|
|
|
|
user = event["user"]
|
|
|
|
nick = user.nickname
|
|
|
|
uid = user.get_id()
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
if self.is_duck_channel(channel) == False:
|
|
|
|
return
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-22 18:10:52 +00:00
|
|
|
if self.is_duck_visible(event, False) == False:
|
2018-09-08 15:15:43 +00:00
|
|
|
if self.should_kick(event):
|
|
|
|
self.kick_bang(event)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-09-22 18:10:52 +00:00
|
|
|
|
|
|
|
self.clear_ducks(channel)
|
2018-09-08 15:15:43 +00:00
|
|
|
return
|
2018-08-31 03:35:42 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.games["ducks"][
|
|
|
|
"next_duck_time"] = self.generate_next_duck_time()
|
|
|
|
channel.games["ducks"]["duck_spawned"] = 0
|
2018-08-31 03:35:42 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
total_shot = channel.get_user_setting(uid, "ducks-shot", 0)
|
|
|
|
total_shot = total_shot + 1
|
2018-08-31 03:14:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
channel.set_user_setting(uid, "ducks-shot", total_shot)
|
2018-08-31 05:27:41 +00:00
|
|
|
|
2018-09-09 02:07:21 +00:00
|
|
|
msg = "Pow! %s shot a duck! You've shot %s ducks in %s!" \
|
2018-09-09 07:59:36 +00:00
|
|
|
% (Utils.bold(nick), Utils.bold(total_shot),
|
|
|
|
Utils.bold(channel.name))
|
2018-09-09 02:07:21 +00:00
|
|
|
|
|
|
|
event["stdout"].write(msg)
|
2018-09-01 19:43:46 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
self.clear_ducks(channel)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-09-01 19:44:56 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.duckstats")
|
2018-09-01 19:43:46 +00:00
|
|
|
def duck_stats(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Show your duck stats
|
|
|
|
"""
|
2018-09-01 19:43:46 +00:00
|
|
|
user = event["user"]
|
|
|
|
channel = event["target"].name
|
|
|
|
nick = user.nickname
|
2018-09-05 11:58:12 +00:00
|
|
|
id = user.get_id()
|
2018-09-01 19:43:46 +00:00
|
|
|
|
2018-09-08 18:10:09 +00:00
|
|
|
poached = user.get_channel_settings_per_setting("ducks-shot", [])
|
|
|
|
friends = user.get_channel_settings_per_setting("ducks-befriended", [])
|
2018-09-01 19:43:46 +00:00
|
|
|
|
|
|
|
channel_friends = 0
|
|
|
|
channel_poached = 0
|
|
|
|
|
|
|
|
total_friends = 0
|
|
|
|
total_poached = 0
|
|
|
|
|
|
|
|
for room, number in friends:
|
|
|
|
if room == channel:
|
|
|
|
channel_friends = number
|
|
|
|
total_friends += number
|
|
|
|
else:
|
|
|
|
total_friends += number
|
|
|
|
|
|
|
|
for room, number in poached:
|
|
|
|
if room == channel:
|
|
|
|
channel_poached = number
|
|
|
|
total_poached += number
|
|
|
|
else:
|
|
|
|
total_poached += number
|
|
|
|
|
2018-09-09 02:07:21 +00:00
|
|
|
tf = total_friends
|
|
|
|
tp = total_poached
|
|
|
|
cp = channel_poached
|
|
|
|
cf = channel_friends
|
|
|
|
|
|
|
|
msg = "%s ducks killed (%s in %s), and %s ducks befriended (%s in %s)" \
|
2018-09-09 07:59:36 +00:00
|
|
|
% (Utils.bold(tp), Utils.bold(cp), Utils.bold(channel),
|
|
|
|
Utils.bold(tf), Utils.bold(cf), Utils.bold(channel))
|
2018-09-09 02:07:21 +00:00
|
|
|
|
|
|
|
event["stdout"].write(Utils.bold(nick) + ": " + msg)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-09-01 19:43:46 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.killers")
|
2018-09-08 15:15:43 +00:00
|
|
|
def duck_enemies(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Show the top duck shooters
|
|
|
|
"""
|
2018-09-08 18:10:09 +00:00
|
|
|
the_enemy = event["server"].find_all_user_channel_settings("ducks-shot")
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
notorious = {}
|
|
|
|
enemy_nicks = []
|
|
|
|
enemy_ducks = []
|
|
|
|
|
|
|
|
for i in the_enemy:
|
|
|
|
if i[1] in notorious.keys():
|
|
|
|
notorious[i[1]] += i[2]
|
|
|
|
else:
|
|
|
|
notorious[i[1]] = i[2]
|
|
|
|
|
|
|
|
for user, enemies in sorted(notorious.items(), key=itemgetter(1),
|
|
|
|
reverse=True):
|
|
|
|
enemy_nicks.append(user)
|
|
|
|
enemy_ducks.append(enemies)
|
|
|
|
|
2018-09-09 02:07:21 +00:00
|
|
|
sentence = Utils.bold("Duck Wranglers: ")
|
2018-09-09 00:19:00 +00:00
|
|
|
build = []
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-09 00:19:00 +00:00
|
|
|
length = len(enemy_nicks) if len(enemy_nicks) < 8 else 8
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
for i in range(0, length):
|
2018-09-09 02:39:29 +00:00
|
|
|
nick = Utils.prevent_highlight(enemy_nicks[i])
|
|
|
|
build.append("%s (%s)" \
|
|
|
|
% (Utils.bold(nick),
|
|
|
|
enemy_ducks[i]))
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-09 00:19:00 +00:00
|
|
|
sentence += ", ".join(build)
|
2018-09-01 19:44:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
event["stdout"].write(sentence)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.friends")
|
2018-09-08 15:15:43 +00:00
|
|
|
def duck_friends(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Show the top duck friends
|
|
|
|
"""
|
2018-09-08 15:15:43 +00:00
|
|
|
friends = event["server"].find_all_user_channel_settings(
|
|
|
|
"ducks-befriended")
|
|
|
|
|
|
|
|
friendliest = {}
|
|
|
|
friend_nicks = []
|
|
|
|
friend_ducks = []
|
|
|
|
|
|
|
|
for i in friends:
|
|
|
|
if i[1] in friendliest.keys():
|
|
|
|
friendliest[i[1]] += i[2]
|
|
|
|
else:
|
|
|
|
friendliest[i[1]] = i[2]
|
2018-09-01 19:44:56 +00:00
|
|
|
|
2018-09-08 15:15:43 +00:00
|
|
|
for user, friends in sorted(friendliest.items(), key=itemgetter(1),
|
|
|
|
reverse=True):
|
|
|
|
friend_nicks.append(user)
|
|
|
|
friend_ducks.append(friends)
|
|
|
|
|
2018-09-09 02:07:21 +00:00
|
|
|
sentence = Utils.bold("Duck Friends: ")
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-09 00:19:00 +00:00
|
|
|
length = len(friend_nicks) if len(friend_nicks) < 8 else 8
|
|
|
|
build = []
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
for i in range(0, length):
|
2018-09-09 02:39:29 +00:00
|
|
|
nick = Utils.prevent_highlight(friend_nicks[i])
|
|
|
|
build.append("%s (%s)" \
|
2018-09-09 07:59:36 +00:00
|
|
|
% (Utils.bold(nick),
|
|
|
|
friend_ducks[i])
|
2018-09-09 02:07:21 +00:00
|
|
|
)
|
2018-09-08 15:15:43 +00:00
|
|
|
|
2018-09-09 00:19:00 +00:00
|
|
|
sentence += ", ".join(build)
|
2018-09-08 15:15:43 +00:00
|
|
|
|
|
|
|
event["stdout"].write(sentence)
|
2018-09-22 15:02:39 +00:00
|
|
|
event.eat()
|