Merge pull request #11 from dngfx/master
Lots of module update, and new modules
This commit is contained in:
commit
3ac6af53bc
3 changed files with 147 additions and 60 deletions
29
modules/8all.py
Normal file
29
modules/8all.py
Normal file
|
@ -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="<question>"
|
||||||
|
)
|
||||||
|
|
||||||
|
def decide(selfs, event):
|
||||||
|
event["stdout"].write(random.choice(CHOICES))
|
43
modules/dice.py
Normal file
43
modules/dice.py
Normal file
|
@ -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)
|
135
modules/ducks.py
135
modules/ducks.py
|
@ -1,19 +1,24 @@
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import datetime
|
from threading import Timer
|
||||||
|
import Utils
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import IRCLogging
|
DUCK_LIST = [
|
||||||
|
"・゜゜・。。・゜ ゜\_O< quack!",
|
||||||
DUCK_LAST_SEEN = datetime.datetime.now()
|
"・゜゜・。。・゜ ゜\_o< QUACK!",
|
||||||
|
"・゜゜・。 。・゜゜\_ó< quack!",
|
||||||
|
"・゜゜・。 。・゜゜\_ó< quack quack!",
|
||||||
|
"・゜゜ 。 。・゜ \_ó< bawk!",
|
||||||
|
"・゜゜ 。 。・゜゜\_ó< squawk!",
|
||||||
|
"・ ゜・。 。・゜゜ \_ó< beep beep!"
|
||||||
|
]
|
||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, bot, events):
|
def __init__(self, bot, events):
|
||||||
self.log = IRCLogging.Log
|
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.events = events
|
self.events = events
|
||||||
self.active_duck = 0
|
|
||||||
self.decoy_hooked = 0
|
self.decoy_hooked = 0
|
||||||
|
self.duck_timer = None
|
||||||
|
|
||||||
events.on("received.command.bef").hook(self.duck_bef,
|
events.on("received.command.bef").hook(self.duck_bef,
|
||||||
help="Befriend a duck!")
|
help="Befriend a duck!")
|
||||||
|
@ -24,19 +29,12 @@ class Module(object):
|
||||||
|
|
||||||
events.on("received.command.friends").hook(self.duck_friends,
|
events.on("received.command.friends").hook(self.duck_friends,
|
||||||
help="See who the friendliest people to ducks are!")
|
help="See who the friendliest people to ducks are!")
|
||||||
# events.on("received.command.killers").hook(self.duck_killers,
|
events.on("received.command.killers").hook(self.duck_enemies,
|
||||||
# help="See who shoots the most amount of ducks.")
|
help="See who shoots the most amount of ducks.")
|
||||||
# events.on("received.command.ducks").hook(self.duck_list,
|
# events.on("received.command.ducks").hook(self.duck_list,
|
||||||
# help="Shows a list of the most popular duck superstars.")
|
# 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.duck_times = {}
|
||||||
self.decoys = {}
|
|
||||||
|
|
||||||
tricky = next_duck_time - now.second
|
|
||||||
tricky += ((next_duck_time - (now.minute + 1)) * 2)
|
|
||||||
|
|
||||||
events.on("postboot").on("configure").on(
|
events.on("postboot").on("configure").on(
|
||||||
"channelset").assure_call(setting="ducks-enabled",
|
"channelset").assure_call(setting="ducks-enabled",
|
||||||
|
@ -50,11 +48,17 @@ class Module(object):
|
||||||
"channelset").assure_call(setting="max-duck-time",
|
"channelset").assure_call(setting="max-duck-time",
|
||||||
help="Max seconds before a duck is summoned")
|
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("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):
|
def bootstrap(self, event):
|
||||||
for server in self.bot.servers.values():
|
for server in self.bot.servers.values():
|
||||||
for channel in server.channels.values():
|
for channel in server.channels.values():
|
||||||
|
@ -65,8 +69,8 @@ class Module(object):
|
||||||
min_time = "min-duck-time-%s" % channel.name
|
min_time = "min-duck-time-%s" % channel.name
|
||||||
max_time = "max-duck-time-%s" % channel.name
|
max_time = "max-duck-time-%s" % channel.name
|
||||||
|
|
||||||
min_duck_time = channel.get_setting("min-duck-time", 240)
|
min_duck_time = channel.get_setting("min-duck-time", 20)
|
||||||
max_duck_time = channel.get_setting("max-duck-time", 1200)
|
max_duck_time = channel.get_setting("max-duck-time", 30)
|
||||||
|
|
||||||
min_duck_time = int(min_duck_time) if isinstance(min_duck_time,
|
min_duck_time = int(min_duck_time) if isinstance(min_duck_time,
|
||||||
str) else min_duck_time
|
str) else min_duck_time
|
||||||
|
@ -89,14 +93,46 @@ class Module(object):
|
||||||
max = "max-duck-time-%s" % (channel_name)
|
max = "max-duck-time-%s" % (channel_name)
|
||||||
|
|
||||||
self.bot.log.debug("Attempting to set %s to %s",
|
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",
|
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])
|
return random.randint(self.duck_times[min], self.duck_times[max])
|
||||||
|
|
||||||
def decoy_time(self):
|
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):
|
def duck_friends(self, event):
|
||||||
friends = event["server"].find_all_user_channel_settings(
|
friends = event["server"].find_all_user_channel_settings(
|
||||||
|
@ -160,12 +196,12 @@ class Module(object):
|
||||||
grammar = "" if befriended_ducks == 0 else "s"
|
grammar = "" if befriended_ducks == 0 else "s"
|
||||||
|
|
||||||
event["stdout"].write(
|
event["stdout"].write(
|
||||||
target + ", you've befriended " + str(
|
target + ", you've befriended " + Utils.bold(str(
|
||||||
befriended_ducks + 1) + " duck" + grammar + " in " + event[
|
befriended_ducks + 1)) + " duck" + grammar + " in " +
|
||||||
"target"].name)
|
Utils.bold(event[
|
||||||
|
"target"].name))
|
||||||
|
|
||||||
next_duck_time = self.duck_time(event)
|
self.duck_loop_entry(event)
|
||||||
self.bot.add_timer("duck-appear", next_duck_time, persist=False)
|
|
||||||
|
|
||||||
def duck_bang(self, event):
|
def duck_bang(self, event):
|
||||||
user = event["user"]
|
user = event["user"]
|
||||||
|
@ -189,12 +225,15 @@ class Module(object):
|
||||||
grammar = "" if shot_ducks == 0 else "s"
|
grammar = "" if shot_ducks == 0 else "s"
|
||||||
|
|
||||||
event["stdout"].write(
|
event["stdout"].write(
|
||||||
target + ", you've shot " + str(
|
target + ", you've shot "
|
||||||
shot_ducks + 1) + " duck" + grammar + " in " + event[
|
+ Utils.bold(str(shot_ducks + 1)) + " duck"
|
||||||
"target"].name)
|
+ grammar + " in "
|
||||||
|
+ Utils.bold(event["target"].name))
|
||||||
|
|
||||||
next_duck_time = self.duck_time(event)
|
self.duck_loop_entry(event)
|
||||||
self.bot.add_timer("duck-appear", next_duck_time, persist=False)
|
|
||||||
|
def get_random_duck_time(self):
|
||||||
|
return random.randint(120, 1200)
|
||||||
|
|
||||||
def show_duck(self, event):
|
def show_duck(self, event):
|
||||||
for server in self.bot.servers.values():
|
for server in self.bot.servers.values():
|
||||||
|
@ -212,17 +251,7 @@ class Module(object):
|
||||||
str) else active_duck
|
str) else active_duck
|
||||||
|
|
||||||
if ducks_enabled == 1 and active_duck == 0:
|
if ducks_enabled == 1 and active_duck == 0:
|
||||||
ducks = [
|
channel.send_message(random.choice(DUCK_LIST))
|
||||||
"・゜゜・。。・゜ ゜\_O< quack!",
|
|
||||||
"・゜゜・。。・゜ ゜\_o< QUACK!",
|
|
||||||
"・゜゜・。 。・゜゜\_ó< quack!",
|
|
||||||
"・゜゜・。 。・゜゜\_ó< quack quack!",
|
|
||||||
"・゜゜ 。 。・゜ \_ó< bawk!",
|
|
||||||
"・゜゜ 。 。・゜゜\_ó< squawk!",
|
|
||||||
"・ ゜・。 。・゜゜ \_ó< beep beep!"
|
|
||||||
]
|
|
||||||
|
|
||||||
channel.send_message(random.choice(ducks))
|
|
||||||
|
|
||||||
channel.set_setting("active-duck", 1)
|
channel.set_setting("active-duck", 1)
|
||||||
|
|
||||||
|
@ -232,22 +261,8 @@ class Module(object):
|
||||||
else:
|
else:
|
||||||
channel.set_setting("active-duck", 0)
|
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):
|
def duck_decoy(self, event):
|
||||||
ducks = [
|
event["stdout"].write(random.choice(DUCK_LIST))
|
||||||
"・゜゜・。。・゜ ゜\_O< quack!",
|
|
||||||
"・゜゜・。。・゜ ゜\_o< QUACK!",
|
|
||||||
"・゜゜・。 。・゜゜\_ó< quack!",
|
|
||||||
"・゜゜・。 。・゜゜\_ó< quack quack!",
|
|
||||||
"・゜゜ 。 。・゜ \_ó< bawk!",
|
|
||||||
"・゜゜ 。 。・゜゜\_ó< squawk!",
|
|
||||||
"・ ゜・。 。・゜゜ \_ó< beep beep!"
|
|
||||||
]
|
|
||||||
|
|
||||||
event["channel"].send_message(random.choice(ducks))
|
|
||||||
|
|
||||||
def set_decoy(self, event):
|
def set_decoy(self, event):
|
||||||
channel = event["target"]
|
channel = event["target"]
|
||||||
|
|
Loading…
Reference in a new issue