diff --git a/bots.yaml b/bots.yaml index d60210d..a9f3fe4 100644 --- a/bots.yaml +++ b/bots.yaml @@ -32,6 +32,7 @@ bots: 'matrix.*irc' : "> {message}\nLes vrais font tourner matrix dans un tmux." 'proxmox' : "promox c'est surfait, faut l'autoremove" on_join: 'Unleash the salt' + min_time: 120 Macron: on_ping: - "PARCE QUE C'EST NOTRE PROJEEEET !" @@ -78,5 +79,5 @@ bots: channels: - server: irc.rezometz.org port: 6667 - channel: "#campus" + channel: "#test" bots: [sel, Macron, Patou, Claudy, Chuck] diff --git a/klafirc/bot.py b/klafirc/bot.py index dd503ec..85cdb71 100644 --- a/klafirc/bot.py +++ b/klafirc/bot.py @@ -1,6 +1,7 @@ import re import random import importlib +import datetime class Bot: def __init__(self, nickname): @@ -18,6 +19,8 @@ class Bot: self.on_join = None self.tg_user_match = re.compile('^<\x03..\x02\x02(?P.+)\x03>') self.ping_match = re.compile('^(<.+> )?\@?{name}'.format(name=nickname)) + self.min_time = 30 + self.last_time = datetime.datetime(1,1,1) def add_reaction(self, match, reaction): """Add a reaction to the bot. @@ -68,7 +71,9 @@ class Bot: Returns: Every matched reactions. """ - username = user.split('!')[0] + if (datetime.datetime.now() - self.last_time).total_seconds() < self.min_time: + return [] + username = username.split('!')[0] tg_user_match = self.tg_user_match.match(message) if 'bot' in username.lower() and tg_user_match: username = '@' + tg_user_match.groupdict()['username'] @@ -98,5 +103,8 @@ class Bot: r = r.format(**context) result.append(' : '.join([username, r])) + if len(result) > 0: + self.last_time = datetime.datetime.now() + return result diff --git a/klafirc/bots/.__init__.py.swp b/klafirc/bots/.__init__.py.swp deleted file mode 100644 index ea1c7e5..0000000 Binary files a/klafirc/bots/.__init__.py.swp and /dev/null differ diff --git a/klafirc/bots/.chuck_norris.py.swp b/klafirc/bots/.chuck_norris.py.swp deleted file mode 100644 index d6363dc..0000000 Binary files a/klafirc/bots/.chuck_norris.py.swp and /dev/null differ diff --git a/klafirc/irc.py b/klafirc/irc.py index dedd447..5003011 100644 --- a/klafirc/irc.py +++ b/klafirc/irc.py @@ -1,3 +1,5 @@ +import time + from twisted.words.protocols import irc from twisted.internet import reactor, protocol @@ -42,8 +44,9 @@ class IRCBotFactory(protocol.ClientFactory): self.channel = bot.channel def clientConnectionLost(self, connector, reason): - connector.connect() logger.info("Client connexion lost") + time.sleep(2) + connector.connect() def clientConnectionFailed(self, connector, reason): logger.info("Connection failed : " + reason) diff --git a/klafirc/loader.py b/klafirc/loader.py index bbed231..7007c62 100644 --- a/klafirc/loader.py +++ b/klafirc/loader.py @@ -29,6 +29,7 @@ class Loader: b.add_python_reaction(match, matches[match]) b.on_join = template.get('on_join', None) + b.min_time = template.get('min_time', 30) return b