macron
This commit is contained in:
parent
44bdfb7651
commit
4323798b54
4 changed files with 1695 additions and 18 deletions
|
@ -13,7 +13,7 @@ quotes = [
|
|||
"C'est de la poudre de perlimpinpin."
|
||||
]
|
||||
[match]
|
||||
"tocard" = "Est-ce que je peux dire autocar ?"
|
||||
"[Tt]ocard" = "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 !"
|
||||
[join]
|
|
@ -35,6 +35,10 @@ quotes = [
|
|||
"La soeur du banni : Matthieu, tu peux m'aider sur mon exo de maths ? @lebanni : Flemme, mon temps vaut de l'argent",
|
||||
"<Nanoy> Un JT c'est pas comme des nocturnes FedeRez, ça s'organise pas tout seul."
|
||||
]
|
||||
ping_extra = [
|
||||
"^[sS]el",
|
||||
"^ping sel"
|
||||
]
|
||||
[match]
|
||||
"détruire le monde" = "Manu on fait des collages ?"
|
||||
"imprimante" = "Je pense qu'on devrait reprendre la même imprimante Brother."
|
||||
|
|
1660
klafirc.log
1660
klafirc.log
File diff suppressed because it is too large
Load diff
|
@ -28,6 +28,7 @@ class Bot:
|
|||
for k in self.config["match"].keys():
|
||||
self.add_reaction(k, self.config["match"][k])
|
||||
|
||||
|
||||
self.pings = []
|
||||
for quote in self.config["ping"]["quotes"]:
|
||||
self.add_ping(quote)
|
||||
|
@ -40,6 +41,7 @@ class Bot:
|
|||
self.dispatcher = self.updater.dispatcher
|
||||
|
||||
self.quote_handler = CommandHandler('ping', self.on_ping)
|
||||
self.match_handler = MessageHandler(Filters.text, self.on_message)
|
||||
self.dispatcher.add_handler(self.quote_handler)
|
||||
|
||||
def start(self):
|
||||
|
@ -52,8 +54,26 @@ class Bot:
|
|||
pass
|
||||
|
||||
def on_ping(self, update, context):
|
||||
quote = random.choice(self.config["ping"]["quotes"])
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=quote)
|
||||
c = {
|
||||
"channel": update.effective_chat.title,
|
||||
"name": self.name,
|
||||
"user": update.effective_user.name,
|
||||
"message": update.effective_message.text,
|
||||
}
|
||||
quote = random.choice(self.pings)
|
||||
if callable(quote):
|
||||
quote = quote(self, username, channel, message)
|
||||
else:
|
||||
quote = quote.format(**c)
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=quote, reply_to_message_id=update.effective_message.message_id)
|
||||
|
||||
def on_message(self, update, context):
|
||||
user = update.effective_user
|
||||
channel = update.effective_chat
|
||||
message = update.effective_message
|
||||
answer = self.get_reaction(user, channel, message)
|
||||
for ans in answer:
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=ans)
|
||||
|
||||
def add_reaction(self, match, reaction):
|
||||
"""Add a reaction to the bot.
|
||||
|
@ -88,7 +108,7 @@ class Bot:
|
|||
module = importlib.import_module(module)
|
||||
return getattr(module, callback)
|
||||
|
||||
def get_reaction(self, username, channel, message):
|
||||
def get_reaction(self, user, channel, message):
|
||||
"""Get a reaction to a message.
|
||||
|
||||
Args:
|
||||
|
@ -99,18 +119,19 @@ class Bot:
|
|||
Returns:
|
||||
Every matched reactions.
|
||||
"""
|
||||
if (datetime.datetime.now() - self.last_time).total_seconds() < self.min_time:
|
||||
if (datetime.datetime.now() - self.channels[channel.id]).total_seconds() < self.min_time:
|
||||
return []
|
||||
|
||||
context = {
|
||||
"channel": channel,
|
||||
"channel": channel.title,
|
||||
"name": self.name,
|
||||
"user": username,
|
||||
"message": message,
|
||||
"user": user.name,
|
||||
"message": message.text,
|
||||
}
|
||||
result = []
|
||||
logging.debug("Looking for reactions.")
|
||||
for m in self.reactions.keys():
|
||||
search = m.search(message)
|
||||
search = m.search(message.text)
|
||||
if search:
|
||||
r = self.reactions[m]
|
||||
if callable(r):
|
||||
|
@ -119,15 +140,7 @@ class Bot:
|
|||
r = r.format(**context)
|
||||
result.append(r)
|
||||
|
||||
if not result and self.ping_match.search(message):
|
||||
r = random.choice(self.pings)
|
||||
if callable(r):
|
||||
r = r(self, username, channel, message)
|
||||
else:
|
||||
r = r.format(**context)
|
||||
result.append(" : ".join([username, r]))
|
||||
|
||||
if len(result) > 0:
|
||||
self.last_time = datetime.datetime.now()
|
||||
self.channels[channel.id] = datetime.datetime.now()
|
||||
|
||||
return result
|
||||
|
|
Loading…
Add table
Reference in a new issue