Merge branch 'timer' into 'master'

No spam srxsly 😂😂😂😂😂

See merge request klafyvel/klafirc!7
This commit is contained in:
klafyvel 2018-08-28 21:58:14 +02:00
commit f3f8de456a
6 changed files with 15 additions and 2 deletions

View file

@ -40,6 +40,7 @@ bots:
'tocard' : "Est-ce que je peux dire autocar ?"
'Manu.*\?' : "Tu mappelles monsieur le président de la République, ou monsieur."
'aides sociales' : "Ça coûte un pognon dingue !"
min_time: 30 # in seconds
Patou:
on_ping:
- "En parlant de ça, Centrale ne sait vraiment pas travailler en multicampus"
@ -78,5 +79,5 @@ bots:
channels:
- server: irc.rezometz.org
port: 6667
channel: "#campus"
channel: "#test"
bots: [sel, Macron, Patou, Claudy, Chuck]

View file

@ -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<username>.+)\x03>')
self.ping_match = re.compile('^(<.+> )?\@?{name}'.format(name=nickname))
self.min_time = 0
self.last_time = datetime.datetime(1,1,1)
def add_reaction(self, match, reaction):
"""Add a reaction to the bot.
@ -68,6 +71,8 @@ class Bot:
Returns:
Every matched reactions.
"""
if (datetime.datetime.now() - self.last_time).total_seconds() < self.min_time:
return []
username = user.split('!')[0]
tg_user_match = self.tg_user_match.match(message)
if 'bot' in username.lower() and tg_user_match:
@ -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

Binary file not shown.

Binary file not shown.

View file

@ -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)

View file

@ -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', 20)
return b