From ea4b562cd73485945bc26944026a1a0b4f02ce57 Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Tue, 28 Aug 2018 21:47:28 +0200 Subject: [PATCH 1/2] timers --- bots.yaml | 3 ++- klafirc/bot.py | 10 +++++++++- klafirc/bots/.__init__.py.swp | Bin 12288 -> 0 bytes klafirc/bots/.chuck_norris.py.swp | Bin 12288 -> 0 bytes klafirc/irc.py | 5 ++++- klafirc/loader.py | 1 + 6 files changed, 16 insertions(+), 3 deletions(-) delete mode 100644 klafirc/bots/.__init__.py.swp delete mode 100644 klafirc/bots/.chuck_norris.py.swp 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 ea1c7e55a1fef9edd7f44c6f696db64d27691bd8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI%O-=$a7{>7z_eRA7P-N{4=!S$7xL~JlNNi??nb5#|q!bc1dKs_cP2e8Rps?d( z3;dfjP1Cnco?p^M)3E*i(pO!tEoHkES$@ZZ*T#q3^+d*#AX&`gNwu`Eg@H?hY+uFS z+UMp#e;CjGYGQ1(9mCvBeXUJqoYr2kID8%z2q18zz|19&-D`P%>a4GN>!GRc>u*PH zrVIfD5I_I{1Q0*~0R+xLz!f$5DuZ18hpFut&mk)r5I_I{1Q0*~0R#|0009ILxKx2) zDDrb7vMPJ^|G#JY~`%w@yW)Sv1yJ IZmpThFNnu4p#T5? diff --git a/klafirc/bots/.chuck_norris.py.swp b/klafirc/bots/.chuck_norris.py.swp deleted file mode 100644 index d6363dcf96899adaae6c965078c5afb3edd5181e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&L2eT<6b9gz?h7qk;E^tps9~nSrYhfHSHDJ z9)KgT;36D?1#dDFB#?*x#;IP!^+V>8U;WqyA1AXanU9QhF7r{j{C7=^fB*y@ zAW((L^TTa=_438)tG?HL#!sJ|K42n-KmY;|fB*y_009U<00RGuKqx!(Q4X`!9%#Gm zJAd@;BRU8`00Izz00bZa0SG_<0uX=z1U67Wr9{_{h`vke|Nqy&|9?Ct`X>1*`69WK z+)8dFpCxCKp=4juk*wx#;Q6s-2tWV=5P$##AOHafKmY;|*jxerOLIC@&hS)+QDRNd zCiDlC>IqvjDl;?f%N6t?S6;gzCo^S?&WBuR@6}Wfj)>~AZH-HBO_W=e`o4?WVuSPE zLgkh2T{I*4SVq6Ev=2U#HT%6;2&F%YV^wC+>Y{sl&pos8rJZXZJ7rQ^^qNimwoO@` xvZAyuaJ}^U^SVBDyIp#tLo#E Date: Tue, 28 Aug 2018 21:55:39 +0200 Subject: [PATCH 2/2] ajustement des timers --- bots.yaml | 2 +- klafirc/bot.py | 4 ++-- klafirc/loader.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bots.yaml b/bots.yaml index a9f3fe4..406a1a6 100644 --- a/bots.yaml +++ b/bots.yaml @@ -32,7 +32,6 @@ 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 !" @@ -41,6 +40,7 @@ bots: 'tocard' : "Est-ce que je peux dire autocar ?" 'Manu.*\?' : "Tu m’appelles 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" diff --git a/klafirc/bot.py b/klafirc/bot.py index 85cdb71..832b9f2 100644 --- a/klafirc/bot.py +++ b/klafirc/bot.py @@ -19,7 +19,7 @@ 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.min_time = 0 self.last_time = datetime.datetime(1,1,1) def add_reaction(self, match, reaction): @@ -73,7 +73,7 @@ class Bot: """ if (datetime.datetime.now() - self.last_time).total_seconds() < self.min_time: return [] - username = username.split('!')[0] + username = user.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'] diff --git a/klafirc/loader.py b/klafirc/loader.py index 7007c62..d55ac18 100644 --- a/klafirc/loader.py +++ b/klafirc/loader.py @@ -29,7 +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) + b.min_time = template.get('min_time', 20) return b