This commit is contained in:
Klafyvel 2018-08-28 21:47:28 +02:00
parent 02fa36d1fb
commit ea4b562cd7
6 changed files with 16 additions and 3 deletions

View file

@ -32,6 +32,7 @@ bots:
'matrix.*irc' : "> {message}\nLes vrais font tourner matrix dans un tmux." 'matrix.*irc' : "> {message}\nLes vrais font tourner matrix dans un tmux."
'proxmox' : "promox c'est surfait, faut l'autoremove" 'proxmox' : "promox c'est surfait, faut l'autoremove"
on_join: 'Unleash the salt' on_join: 'Unleash the salt'
min_time: 120
Macron: Macron:
on_ping: on_ping:
- "PARCE QUE C'EST NOTRE PROJEEEET !" - "PARCE QUE C'EST NOTRE PROJEEEET !"
@ -78,5 +79,5 @@ bots:
channels: channels:
- server: irc.rezometz.org - server: irc.rezometz.org
port: 6667 port: 6667
channel: "#campus" channel: "#test"
bots: [sel, Macron, Patou, Claudy, Chuck] bots: [sel, Macron, Patou, Claudy, Chuck]

View file

@ -1,6 +1,7 @@
import re import re
import random import random
import importlib import importlib
import datetime
class Bot: class Bot:
def __init__(self, nickname): def __init__(self, nickname):
@ -18,6 +19,8 @@ class Bot:
self.on_join = None self.on_join = None
self.tg_user_match = re.compile('^<\x03..\x02\x02(?P<username>.+)\x03>') self.tg_user_match = re.compile('^<\x03..\x02\x02(?P<username>.+)\x03>')
self.ping_match = re.compile('^(<.+> )?\@?{name}'.format(name=nickname)) 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): def add_reaction(self, match, reaction):
"""Add a reaction to the bot. """Add a reaction to the bot.
@ -68,7 +71,9 @@ class Bot:
Returns: Returns:
Every matched reactions. 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) tg_user_match = self.tg_user_match.match(message)
if 'bot' in username.lower() and tg_user_match: if 'bot' in username.lower() and tg_user_match:
username = '@' + tg_user_match.groupdict()['username'] username = '@' + tg_user_match.groupdict()['username']
@ -98,5 +103,8 @@ class Bot:
r = r.format(**context) r = r.format(**context)
result.append(' : '.join([username, r])) result.append(' : '.join([username, r]))
if len(result) > 0:
self.last_time = datetime.datetime.now()
return result return result

Binary file not shown.

Binary file not shown.

View file

@ -1,3 +1,5 @@
import time
from twisted.words.protocols import irc from twisted.words.protocols import irc
from twisted.internet import reactor, protocol from twisted.internet import reactor, protocol
@ -42,8 +44,9 @@ class IRCBotFactory(protocol.ClientFactory):
self.channel = bot.channel self.channel = bot.channel
def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
connector.connect()
logger.info("Client connexion lost") logger.info("Client connexion lost")
time.sleep(2)
connector.connect()
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
logger.info("Connection failed : " + reason) logger.info("Connection failed : " + reason)

View file

@ -29,6 +29,7 @@ class Loader:
b.add_python_reaction(match, matches[match]) b.add_python_reaction(match, matches[match])
b.on_join = template.get('on_join', None) b.on_join = template.get('on_join', None)
b.min_time = template.get('min_time', 30)
return b return b