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