mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-26 04:51:09 -05:00
cleanup
This commit is contained in:
parent
c460399e33
commit
ff1e7f596b
@ -32,22 +32,6 @@ class Cayenne(callbacks.Plugin):
|
||||
self.__parent = super(Cayenne, self)
|
||||
self.__parent.__init__(irc)
|
||||
|
||||
self.read_cat_facts_file()
|
||||
|
||||
def read_cat_facts_file(self):
|
||||
"""
|
||||
Read the cat facts file into a list so we can retrieve at random later
|
||||
"""
|
||||
try:
|
||||
dir = os.path.dirname(__file__)
|
||||
fact_file_path = os.path.join(dir, "./facts.txt")
|
||||
|
||||
for line in open(fact_file_path):
|
||||
self.cat_facts.append(line.rstrip("\n"))
|
||||
|
||||
except:
|
||||
self.log.error("Cayenne: error reading cat facts file: %s" % fact_file_path)
|
||||
|
||||
def get_fact(self):
|
||||
"""
|
||||
Get a random cat fact
|
||||
@ -61,17 +45,14 @@ class Cayenne(callbacks.Plugin):
|
||||
which one was found, if any
|
||||
"""
|
||||
words = self.registryValue("triggerWords")
|
||||
|
||||
if words:
|
||||
words = [word.strip() for word in words]
|
||||
|
||||
if words:
|
||||
for word in words:
|
||||
if word and word in message:
|
||||
return word
|
||||
else:
|
||||
self.log.error("Cayenne: no trigger words set apparently")
|
||||
|
||||
return False
|
||||
|
||||
def get_link(self):
|
||||
@ -98,13 +79,10 @@ class Cayenne(callbacks.Plugin):
|
||||
is_ctcp = ircmsgs.isCtcp(msg)
|
||||
message = msg.args[1]
|
||||
bot_nick = irc.nick
|
||||
|
||||
# Check origin nick to make sure the trigger
|
||||
# didn"t come from the bot.
|
||||
origin_nick = msg.nick
|
||||
|
||||
is_message_from_self = origin_nick.lower() == bot_nick.lower()
|
||||
|
||||
# Only react to messages/actions in a channel and to messages that aren't from
|
||||
# the bot itself.
|
||||
if is_channel and not is_ctcp and not is_message_from_self and self.registryValue('enable', channel):
|
||||
@ -115,36 +93,27 @@ class Cayenne(callbacks.Plugin):
|
||||
triggered = self.message_contains_trigger_word(message)
|
||||
now = datetime.datetime.now()
|
||||
seconds = 0
|
||||
|
||||
if self.last_message_timestamp:
|
||||
seconds = (now - self.last_message_timestamp).total_seconds()
|
||||
throttled = seconds < throttle_seconds
|
||||
else:
|
||||
throttled = False
|
||||
|
||||
if triggered is not False:
|
||||
self.log.debug("Cayenne triggered because message contained %s" % (triggered))
|
||||
|
||||
fact_rand = random.randrange(0, 100) <= fact_chance
|
||||
link_rand = random.randrange(0, 100) <= link_chance
|
||||
|
||||
if fact_rand or link_rand:
|
||||
if throttled:
|
||||
self.log.info("Cayenne throttled. Not meowing: it has been %s seconds" % (round(seconds, 1)))
|
||||
else:
|
||||
self.last_message_timestamp = now
|
||||
|
||||
if fact_rand:
|
||||
output = self.get_fact()
|
||||
|
||||
if link_rand:
|
||||
output = self.get_link()
|
||||
|
||||
if output:
|
||||
irc.sendMsg(ircmsgs.privmsg(channel, output))
|
||||
else:
|
||||
self.log.error("Cayenne: error retrieving output")
|
||||
|
||||
Class = Cayenne
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user