diff --git a/modules/8all.py b/modules/8all.py new file mode 100644 index 00000000..57be2da4 --- /dev/null +++ b/modules/8all.py @@ -0,0 +1,29 @@ +import random + +CHOICES = [ + "Definitely", + "Yes", + "Probably", + "Maybe", + "Probably not", + "No", + "Definitely not", + "I don't know", + "Ask again later", + "The answer is unclear", + "Absolutely", + "Dubious at best", + "I'm on a break, ask again later" +] + +class Module(object): + def __init__(self, bot, events): + events.on("received.command.8ball").hook( + self.decide, + min_args=1, + help="Ask the mystic 8ball a question!", + usage="" + ) + + def decide(selfs, event): + event["stdout"].write(random.choice(CHOICES)) diff --git a/modules/dice.py b/modules/dice.py new file mode 100644 index 00000000..2829cf48 --- /dev/null +++ b/modules/dice.py @@ -0,0 +1,43 @@ +import random +import Utils + +class Module(object): + def __init__(self, bot, events): + events.on("received.command.roll").hook( + self.roll_dice, + min_args=1, + help="Roll some dice, DND style!", + usage="[1-5]d[1-20]" + ) + + self.err_msg = "Incorrectly formatted dice! Format must be [number]d[number], for example, 1d20" + + def roll_dice(self, event): + raw_input = event["args_split"][0] + roll = raw_input.split("d") + results = [] + + if len(roll) is not 2: + event["stderr"].write(self.err_msg) + return + + if roll[0].isdigit() is False or roll[1].isdigit() is False: + event["stderr"].write(self.err_msg) + return + + roll = [int(roll[0]), int(roll[1])] + + num_of_die = 5 if roll[0] > 5 else roll[0] + sides_of_die = 20 if roll[1] > 20 else roll[1] + + str_roll = str(num_of_die) + "d" + str(sides_of_die) + + for i in range(0, num_of_die): + results.append(random.randint(1, sides_of_die)) + + total = sum(results) + results = ', '.join(map(str, results)) + + event["stdout"].write("Rolled " + Utils.bold(str_roll) + " for a total " + + "of " + Utils.bold(str(total)) + + ": " + results) diff --git a/modules/ducks.py b/modules/ducks.py index 54b5bc61..44b03d00 100644 --- a/modules/ducks.py +++ b/modules/ducks.py @@ -1,19 +1,24 @@ from operator import itemgetter -import datetime +from threading import Timer +import Utils import random -import IRCLogging - -DUCK_LAST_SEEN = datetime.datetime.now() - +DUCK_LIST = [ + "・゜゜・。。・゜ ​ ゜\_O​< q​uack!", + "・゜゜・。。・゜ ​ ゜\_o< QUACK!", + "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack!", + "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack quack!", + "・゜゜ 。 ​ 。・゜ \​_ó< bawk!", + "・゜゜ 。 ​ 。・゜゜\​_ó< squawk!", + "・ ゜・。 ​ 。・゜゜ \​_ó< beep beep!" +] class Module(object): def __init__(self, bot, events): - self.log = IRCLogging.Log self.bot = bot self.events = events - self.active_duck = 0 self.decoy_hooked = 0 + self.duck_timer = None events.on("received.command.bef").hook(self.duck_bef, help="Befriend a duck!") @@ -24,19 +29,12 @@ class Module(object): events.on("received.command.friends").hook(self.duck_friends, help="See who the friendliest people to ducks are!") - # events.on("received.command.killers").hook(self.duck_killers, - # help="See who shoots the most amount of ducks.") + events.on("received.command.killers").hook(self.duck_enemies, + help="See who shoots the most amount of ducks.") # events.on("received.command.ducks").hook(self.duck_list, # help="Shows a list of the most popular duck superstars.") - now = datetime.datetime.now() - next_duck_time = random.randint(30, 40) - self.duck_times = {} - self.decoys = {} - - tricky = next_duck_time - now.second - tricky += ((next_duck_time - (now.minute + 1)) * 2) events.on("postboot").on("configure").on( "channelset").assure_call(setting="ducks-enabled", @@ -50,11 +48,17 @@ class Module(object): "channelset").assure_call(setting="max-duck-time", help="Max seconds before a duck is summoned") - events.on("timer").on("duck-appear").hook(self.show_duck) - bot.add_timer("duck-appear", next_duck_time, persist=False) - events.on("received.numeric.366").hook(self.bootstrap) + events.on("raw").on("376").hook(self.duck_loop_entry) + + def duck_loop_entry(self, event): + wait = self.get_random_duck_time() + self.timer = Timer(wait, self.show_duck, [event]) + self.bot.log.info("Sending out a wave of ducks in %s seconds", + [wait]) + self.timer.start() + def bootstrap(self, event): for server in self.bot.servers.values(): for channel in server.channels.values(): @@ -65,8 +69,8 @@ class Module(object): min_time = "min-duck-time-%s" % channel.name max_time = "max-duck-time-%s" % channel.name - min_duck_time = channel.get_setting("min-duck-time", 240) - max_duck_time = channel.get_setting("max-duck-time", 1200) + min_duck_time = channel.get_setting("min-duck-time", 20) + max_duck_time = channel.get_setting("max-duck-time", 30) min_duck_time = int(min_duck_time) if isinstance(min_duck_time, str) else min_duck_time @@ -89,14 +93,46 @@ class Module(object): max = "max-duck-time-%s" % (channel_name) self.bot.log.debug("Attempting to set %s to %s", - [str(min), str(self.duck_times[min])]); + [str(min), str(self.duck_times[min])]) self.bot.log.debug("Attempting to set %s to %s", - [str(max), str(self.duck_times[max])]); + [str(max), str(self.duck_times[max])]) return random.randint(self.duck_times[min], self.duck_times[max]) def decoy_time(self): - return random.randint(10, 20) + return random.randint(60, 180) + + def duck_enemies(self, event): + the_enemy = event["server"].find_all_user_channel_settings( + "ducks-shot") + + 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) + + sentence = "Most Notorious Users -- " + + length = len(enemy_nicks) if len(enemy_nicks) < 11 else 11 + + for i in range(0, length): + sentence += enemy_nicks[i] + " (" + str(enemy_ducks[i]) + ")" + if i < 10: + sentence += ", " + + sentence = sentence[0:-2] + + event["stdout"].write(sentence) def duck_friends(self, event): friends = event["server"].find_all_user_channel_settings( @@ -160,12 +196,12 @@ class Module(object): grammar = "" if befriended_ducks == 0 else "s" event["stdout"].write( - target + ", you've befriended " + str( - befriended_ducks + 1) + " duck" + grammar + " in " + event[ - "target"].name) + target + ", you've befriended " + Utils.bold(str( + befriended_ducks + 1)) + " duck" + grammar + " in " + + Utils.bold(event[ + "target"].name)) - next_duck_time = self.duck_time(event) - self.bot.add_timer("duck-appear", next_duck_time, persist=False) + self.duck_loop_entry(event) def duck_bang(self, event): user = event["user"] @@ -189,12 +225,15 @@ class Module(object): grammar = "" if shot_ducks == 0 else "s" event["stdout"].write( - target + ", you've shot " + str( - shot_ducks + 1) + " duck" + grammar + " in " + event[ - "target"].name) + target + ", you've shot " + + Utils.bold(str(shot_ducks + 1)) + " duck" + + grammar + " in " + + Utils.bold(event["target"].name)) - next_duck_time = self.duck_time(event) - self.bot.add_timer("duck-appear", next_duck_time, persist=False) + self.duck_loop_entry(event) + + def get_random_duck_time(self): + return random.randint(120, 1200) def show_duck(self, event): for server in self.bot.servers.values(): @@ -212,17 +251,7 @@ class Module(object): str) else active_duck if ducks_enabled == 1 and active_duck == 0: - ducks = [ - "・゜゜・。。・゜ ​ ゜\_O​< q​uack!", - "・゜゜・。。・゜ ​ ゜\_o< QUACK!", - "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack!", - "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack quack!", - "・゜゜ 。 ​ 。・゜ \​_ó< bawk!", - "・゜゜ 。 ​ 。・゜゜\​_ó< squawk!", - "・ ゜・。 ​ 。・゜゜ \​_ó< beep beep!" - ] - - channel.send_message(random.choice(ducks)) + channel.send_message(random.choice(DUCK_LIST)) channel.set_setting("active-duck", 1) @@ -232,22 +261,8 @@ class Module(object): else: channel.set_setting("active-duck", 0) - next_duck_time = self.duck_time(channel.name) - self.bot.add_timer("duck-appear", next_duck_time, - persist=False) - def duck_decoy(self, event): - ducks = [ - "・゜゜・。。・゜ ​ ゜\_O​< q​uack!", - "・゜゜・。。・゜ ​ ゜\_o< QUACK!", - "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack!", - "・゜゜・。 ​ 。・゜゜\​_ó< qu​ack quack!", - "・゜゜ 。 ​ 。・゜ \​_ó< bawk!", - "・゜゜ 。 ​ 。・゜゜\​_ó< squawk!", - "・ ゜・。 ​ 。・゜゜ \​_ó< beep beep!" - ] - - event["channel"].send_message(random.choice(ducks)) + event["stdout"].write(random.choice(DUCK_LIST)) def set_decoy(self, event): channel = event["target"]