2018-08-31 03:35:42 +00:00
|
|
|
|
import datetime
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
import IRCLogging
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
DUCK_LAST_SEEN = datetime.datetime.now()
|
|
|
|
|
|
2018-08-31 03:35:42 +00:00
|
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
|
class Module(object):
|
2018-08-31 11:55:52 +00:00
|
|
|
|
def __init__(self, bot, events):
|
2018-08-31 03:14:56 +00:00
|
|
|
|
self.log = IRCLogging.Log
|
|
|
|
|
self.bot = bot
|
2018-08-31 11:55:52 +00:00
|
|
|
|
self.events = events
|
2018-08-31 03:14:56 +00:00
|
|
|
|
self.active_duck = 0
|
2018-08-31 13:10:15 +00:00
|
|
|
|
self.decoy_hooked = 0
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("received.command.bef").hook(self.duck_bef,
|
2018-08-31 03:35:42 +00:00
|
|
|
|
help="Befriend a duck!")
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("received.command.bang").hook(self.duck_bang,
|
2018-08-31 03:14:56 +00:00
|
|
|
|
help="Shoot a duck! Meanie.")
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("received.command.decoy").hook(self.set_decoy,
|
2018-08-31 05:27:41 +00:00
|
|
|
|
help="Be a sneaky fellow and make a decoy duck.")
|
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
# events.on("received.command.friends").hook(self.duck_friends,
|
2018-08-31 03:35:42 +00:00
|
|
|
|
# help="See who the friendliest people to ducks are!")
|
2018-08-31 11:55:52 +00:00
|
|
|
|
# events.on("received.command.killers").hook(self.duck_killers,
|
2018-08-31 03:35:42 +00:00
|
|
|
|
# help="See who shoots the most amount of ducks.")
|
2018-08-31 11:55:52 +00:00
|
|
|
|
# events.on("received.command.ducks").hook(self.duck_list,
|
2018-08-31 03:35:42 +00:00
|
|
|
|
# help="Shows a list of the most popular duck superstars.")
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
|
next_duck_time = random.randint(30, 40)
|
|
|
|
|
|
|
|
|
|
self.duck_times = {}
|
2018-08-31 05:27:41 +00:00
|
|
|
|
self.decoys = {}
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
tricky = next_duck_time - now.second
|
2018-08-31 03:35:42 +00:00
|
|
|
|
tricky += ((next_duck_time - (now.minute + 1)) * 2)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("postboot").on("configure").on(
|
2018-08-31 03:14:56 +00:00
|
|
|
|
"channelset").assure_call(setting="ducks-enabled",
|
|
|
|
|
help="Toggles ducks! (1 or 0)")
|
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("postboot").on("configure").on(
|
2018-08-31 03:14:56 +00:00
|
|
|
|
"channelset").assure_call(setting="min-duck-time",
|
|
|
|
|
help="Minimum seconds before a duck is summoned")
|
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("postboot").on("configure").on(
|
2018-08-31 03:14:56 +00:00
|
|
|
|
"channelset").assure_call(setting="max-duck-time",
|
|
|
|
|
help="Max seconds before a duck is summoned")
|
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("timer").on("duck-appear").hook(self.show_duck)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
bot.add_timer("duck-appear", next_duck_time, persist=False)
|
|
|
|
|
|
2018-08-31 11:55:52 +00:00
|
|
|
|
events.on("received.numeric.366").hook(self.bootstrap)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
def bootstrap(self, event):
|
|
|
|
|
for server in self.bot.servers.values():
|
|
|
|
|
for channel in server.channels.values():
|
|
|
|
|
ducks_enabled = channel.get_setting("ducks-enabled", 0)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
ducks_enabled = int(ducks_enabled) if isinstance(ducks_enabled, str) else ducks_enabled
|
2018-08-31 04:48:53 +00:00
|
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2018-08-31 09:51:47 +00:00
|
|
|
|
min_duck_time = int(min_duck_time) if isinstance(min_duck_time, str) else min_duck_time
|
|
|
|
|
max_duck_time = int(max_duck_time) if isinstance(max_duck_time, str) else max_duck_time
|
2018-08-31 04:48:53 +00:00
|
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
|
self.duck_times[min_time] = min_duck_time
|
|
|
|
|
self.duck_times[max_time] = max_duck_time
|
|
|
|
|
|
|
|
|
|
if ducks_enabled == 1:
|
|
|
|
|
channel.set_setting("active-duck", 0)
|
|
|
|
|
|
|
|
|
|
def duck_time(self, channel):
|
|
|
|
|
if isinstance(channel, str):
|
|
|
|
|
channel_name = channel
|
|
|
|
|
else:
|
|
|
|
|
channel_name = channel["target"].name
|
|
|
|
|
|
|
|
|
|
min = "min-duck-time-%s" % (channel_name)
|
|
|
|
|
max = "max-duck-time-%s" % (channel_name)
|
|
|
|
|
|
2018-08-31 09:51:47 +00:00
|
|
|
|
self.bot.log.debug("Attempting to set %s to %s", [str(min), str(self.duck_times[min])]);
|
|
|
|
|
self.bot.log.debug("Attempting to set %s to %s", [str(max), str(self.duck_times[max])]);
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
return random.randint(self.duck_times[min], self.duck_times[max])
|
|
|
|
|
|
2018-08-31 05:27:41 +00:00
|
|
|
|
def decoy_time(self):
|
2018-08-31 12:58:44 +00:00
|
|
|
|
return random.randint(10, 20)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
|
2018-08-31 05:27:41 +00:00
|
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
|
def duck_bef(self, event):
|
|
|
|
|
target = event["user"].nickname
|
2018-08-31 04:48:53 +00:00
|
|
|
|
active_duck = event["target"].get_setting("active-duck", 0)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
active_duck = int(active_duck) if isinstance(active_duck, str) else active_duck
|
2018-08-31 04:48:53 +00:00
|
|
|
|
|
|
|
|
|
if active_duck == 0:
|
2018-08-31 03:14:56 +00:00
|
|
|
|
event["stderr"].set_prefix("Kick")
|
|
|
|
|
if event["server"].has_user(target):
|
|
|
|
|
if not event["server"].is_own_nickname(target):
|
2018-08-31 09:51:47 +00:00
|
|
|
|
event["target"].send_kick(target, "You tried befriending a non-existent duck. Creepy!")
|
2018-08-31 03:14:56 +00:00
|
|
|
|
else:
|
|
|
|
|
event["stderr"].write("Nope.")
|
|
|
|
|
else:
|
|
|
|
|
event["stderr"].write("That user is not in this channel")
|
|
|
|
|
else:
|
|
|
|
|
setting = "bef-ducks-%s-%s" % (target, event["target"].name)
|
|
|
|
|
befriended_ducks = event["server"].get_setting(setting, 0)
|
|
|
|
|
event["server"].set_setting(setting, befriended_ducks + 1)
|
|
|
|
|
event["target"].set_setting("active-duck", 0)
|
|
|
|
|
|
|
|
|
|
grammar = "" if befriended_ducks == 0 else "s"
|
|
|
|
|
|
2018-08-31 03:35:42 +00:00
|
|
|
|
event["stdout"].write(
|
2018-08-31 09:51:47 +00:00
|
|
|
|
target + ", you've befriended " + str(befriended_ducks + 1) + " duck" + grammar + " in " + event[
|
|
|
|
|
"target"].name);
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
next_duck_time = self.duck_time(event)
|
|
|
|
|
self.bot.add_timer("duck-appear", next_duck_time, persist=False)
|
|
|
|
|
|
|
|
|
|
def duck_bang(self, event):
|
|
|
|
|
target = event["user"].nickname
|
|
|
|
|
if event["target"].get_setting("active-duck", 0) == 0:
|
|
|
|
|
event["stderr"].set_prefix("Kick")
|
|
|
|
|
if event["server"].has_user(target):
|
|
|
|
|
if not event["server"].is_own_nickname(target):
|
2018-08-31 09:51:47 +00:00
|
|
|
|
event["target"].send_kick(target, "You tried shooting a non-existent duck. Creepy!")
|
2018-08-31 03:14:56 +00:00
|
|
|
|
else:
|
|
|
|
|
event["stderr"].write("Nope.")
|
|
|
|
|
else:
|
|
|
|
|
event["stderr"].write("That user is not in this channel")
|
|
|
|
|
else:
|
|
|
|
|
setting = "shot-ducks-%s-%s" % (target, event["target"].name)
|
|
|
|
|
shot_ducks = event["server"].get_setting(setting, 0)
|
|
|
|
|
event["server"].set_setting(setting, shot_ducks + 1)
|
|
|
|
|
event["target"].set_setting("active-duck", 0)
|
|
|
|
|
|
|
|
|
|
grammar = "" if shot_ducks == 0 else "s"
|
|
|
|
|
|
2018-08-31 03:35:42 +00:00
|
|
|
|
event["stdout"].write(
|
2018-08-31 09:51:47 +00:00
|
|
|
|
target + ", you've shot " + str(shot_ducks + 1) + " duck" + grammar + " in " + event["target"].name);
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
next_duck_time = self.duck_time(event)
|
|
|
|
|
self.bot.add_timer("duck-appear", next_duck_time, persist=False)
|
|
|
|
|
|
|
|
|
|
def show_duck(self, event):
|
|
|
|
|
for server in self.bot.servers.values():
|
|
|
|
|
for channel in server.channels.values():
|
|
|
|
|
ducks_enabled = channel.get_setting("ducks-enabled", 0)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
ducks_enabled = int(ducks_enabled) if isinstance(ducks_enabled, str) else ducks_enabled
|
2018-08-31 03:35:42 +00:00
|
|
|
|
if ducks_enabled == 0:
|
|
|
|
|
continue
|
|
|
|
|
|
2018-08-31 09:51:47 +00:00
|
|
|
|
self.bot.log.info("Ducks enabled for %s: %s", [str(channel.name), str(ducks_enabled)])
|
2018-08-31 03:14:56 +00:00
|
|
|
|
active_duck = channel.get_setting("active-duck", 0)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
active_duck = int(active_duck) if isinstance(active_duck, str) else active_duck
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
|
|
|
|
if ducks_enabled == 1 and active_duck == 0:
|
|
|
|
|
ducks = [
|
|
|
|
|
"・゜゜・。。・゜ ゜\_O< quack!",
|
|
|
|
|
"・゜゜・。。・゜ ゜\_o< QUACK!",
|
|
|
|
|
"・゜゜・。 。・゜゜\_ó< quack!",
|
|
|
|
|
"・゜゜・。 。・゜゜\_ó< quack quack!",
|
|
|
|
|
"・゜゜ 。 。・゜ \_ó< bawk!",
|
|
|
|
|
"・゜゜ 。 。・゜゜\_ó< squawk!",
|
|
|
|
|
"・ ゜・。 。・゜゜ \_ó< beep beep!"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
channel.send_message(random.choice(ducks))
|
|
|
|
|
|
|
|
|
|
channel.set_setting("active-duck", 1)
|
2018-08-31 03:35:42 +00:00
|
|
|
|
|
|
|
|
|
elif ducks_enabled == 1 and active_duck == 1:
|
|
|
|
|
pass
|
|
|
|
|
|
2018-08-31 03:14:56 +00:00
|
|
|
|
else:
|
|
|
|
|
channel.set_setting("active-duck", 0)
|
|
|
|
|
|
|
|
|
|
next_duck_time = self.duck_time(channel.name)
|
2018-08-31 09:51:47 +00:00
|
|
|
|
self.bot.add_timer("duck-appear", next_duck_time, persist=False)
|
2018-08-31 03:14:56 +00:00
|
|
|
|
|
2018-08-31 05:27:41 +00:00
|
|
|
|
def duck_decoy(self, event):
|
|
|
|
|
ducks = [
|
|
|
|
|
"・゜゜・。。・゜ ゜\_O< quack!",
|
|
|
|
|
"・゜゜・。。・゜ ゜\_o< QUACK!",
|
|
|
|
|
"・゜゜・。 。・゜゜\_ó< quack!",
|
|
|
|
|
"・゜゜・。 。・゜゜\_ó< quack quack!",
|
|
|
|
|
"・゜゜ 。 。・゜ \_ó< bawk!",
|
|
|
|
|
"・゜゜ 。 。・゜゜\_ó< squawk!",
|
|
|
|
|
"・ ゜・。 。・゜゜ \_ó< beep beep!"
|
|
|
|
|
]
|
|
|
|
|
|
2018-08-31 12:58:44 +00:00
|
|
|
|
event["channel"].send_message(random.choice(ducks))
|
2018-08-31 05:27:41 +00:00
|
|
|
|
|
|
|
|
|
def set_decoy(self, event):
|
2018-08-31 13:00:09 +00:00
|
|
|
|
channel = event["target"]
|
2018-08-31 12:58:44 +00:00
|
|
|
|
|
2018-08-31 05:27:41 +00:00
|
|
|
|
next_decoy_time = self.decoy_time()
|
2018-08-31 13:10:15 +00:00
|
|
|
|
|
|
|
|
|
if self.decoy_hooked == 0:
|
|
|
|
|
self.events.on("timer").on("duck-decoy").hook(self.duck_decoy)
|
|
|
|
|
self.decoy_hooked = 1
|
|
|
|
|
|
2018-08-31 12:58:44 +00:00
|
|
|
|
self.bot.add_timer("duck-decoy", next_decoy_time, None, None, False,
|
|
|
|
|
channel=channel)
|
2018-08-31 05:27:41 +00:00
|
|
|
|
|
|
|
|
|
# def coins(self, event):
|
|
|
|
|
# if event["args_split"]:
|
|
|
|
|
# target = event["server"].get_user(event["args_split"][0])
|
|
|
|
|
# else:
|
|
|
|
|
# target = event["user"]
|
|
|
|
|
# coins = decimal.Decimal(target.get_setting("coins", "0.0"))
|
|
|
|
|
# event["stdout"].write("%s has %s coin%s" % (target.nickname,
|
|
|
|
|
# "{0:.2f}".format(coins), "" if coins == 1 else "s"))
|