Apparently i auto-reformatted the code. Either way I fixed ducks spawning endlessly.

This commit is contained in:
dngfx 2018-08-31 04:35:42 +01:00
parent 8d6f0fffa9
commit a635b1f0a0

View file

@ -1,8 +1,11 @@
import datetime, time import datetime
import random, IRCLogging import random
import IRCLogging
DUCK_LAST_SEEN = datetime.datetime.now() DUCK_LAST_SEEN = datetime.datetime.now()
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot):
self.log = IRCLogging.Log self.log = IRCLogging.Log
@ -45,7 +48,6 @@ class Module(object):
bot.events.on("received.numeric.366").hook(self.bootstrap) bot.events.on("received.numeric.366").hook(self.bootstrap)
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():
@ -97,12 +99,13 @@ class Module(object):
grammar = "" if befriended_ducks == 0 else "s" grammar = "" if befriended_ducks == 0 else "s"
event["stdout"].write(target + ", you've befriended " + str(befriended_ducks + 1) + " duck" + grammar + " in " + event["target"].name); event["stdout"].write(
target + ", you've befriended " + str(befriended_ducks + 1) + " duck" + grammar + " in " + event[
"target"].name);
next_duck_time = self.duck_time(event) next_duck_time = self.duck_time(event)
self.bot.add_timer("duck-appear", next_duck_time, persist=False) self.bot.add_timer("duck-appear", next_duck_time, persist=False)
def duck_bang(self, event): def duck_bang(self, event):
target = event["user"].nickname target = event["user"].nickname
if event["target"].get_setting("active-duck", 0) == 0: if event["target"].get_setting("active-duck", 0) == 0:
@ -122,7 +125,8 @@ class Module(object):
grammar = "" if shot_ducks == 0 else "s" grammar = "" if shot_ducks == 0 else "s"
event["stdout"].write(target + ", you've shot " + str(shot_ducks + 1) + " duck" + grammar + " in " + event["target"].name); event["stdout"].write(
target + ", you've shot " + str(shot_ducks + 1) + " duck" + grammar + " in " + event["target"].name);
next_duck_time = self.duck_time(event) next_duck_time = self.duck_time(event)
self.bot.add_timer("duck-appear", next_duck_time, persist=False) self.bot.add_timer("duck-appear", next_duck_time, persist=False)
@ -131,6 +135,9 @@ class Module(object):
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():
ducks_enabled = channel.get_setting("ducks-enabled", 0) ducks_enabled = channel.get_setting("ducks-enabled", 0)
if ducks_enabled == 0:
continue
self.bot.log.info("Ducks enabled for %s: %s", [str(channel.name), str(ducks_enabled)]) self.bot.log.info("Ducks enabled for %s: %s", [str(channel.name), str(ducks_enabled)])
active_duck = channel.get_setting("active-duck", 0) active_duck = channel.get_setting("active-duck", 0)
@ -148,14 +155,16 @@ class Module(object):
channel.send_message(random.choice(ducks)) channel.send_message(random.choice(ducks))
channel.set_setting("active-duck", 1) channel.set_setting("active-duck", 1)
elif ducks_enabled == 1 and active_duck == 1:
pass
else: else:
channel.set_setting("active-duck", 0) channel.set_setting("active-duck", 0)
next_duck_time = self.duck_time(channel.name) next_duck_time = self.duck_time(channel.name)
self.bot.add_timer("duck-appear", next_duck_time, persist=False) self.bot.add_timer("duck-appear", next_duck_time, persist=False)
# def coins(self, event): # def coins(self, event):
# if event["args_split"]: # if event["args_split"]:
# target = event["server"].get_user(event["args_split"][0]) # target = event["server"].get_user(event["args_split"][0])