forked from mindiell/hebdobot
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from dataclasses import dataclass
|
|
import time
|
|
|
|
from bot.hooks import hooks
|
|
from bot.review.review import Review
|
|
|
|
|
|
@dataclass
|
|
class Answer:
|
|
target: str
|
|
message: str
|
|
|
|
|
|
class Hebdobot:
|
|
def __init__(self, settings, channel, nickname="hebdobot"):
|
|
self.settings = settings
|
|
self.channel = channel
|
|
self.nickname = nickname
|
|
self.answers = []
|
|
|
|
# Gestion de la revue hebdomadaire
|
|
self.review = Review()
|
|
|
|
def on_private_message(self, channel, sender, message):
|
|
"""
|
|
Tous les messages privés sont ignorés. Si l'utilisateur tente une commande, on
|
|
lui signale de le faire plutôt sur le canal public.
|
|
"""
|
|
self.answers = []
|
|
if message[0] == "!":
|
|
self.send(sender, "vos commandes dans le salon public")
|
|
|
|
return self.answers
|
|
|
|
def on_public_message(self, channel, sender, message):
|
|
"""
|
|
Tous les messages publics sont pris en compte. On utilise les hooks chargés au
|
|
démarrage pour cela.
|
|
"""
|
|
self.answers = []
|
|
if self.review.is_started:
|
|
self.review.add_message(sender, message)
|
|
|
|
for hook in hooks:
|
|
if hook.process(self, channel, sender, message):
|
|
break
|
|
|
|
return self.answers
|
|
|
|
def send(self, target, message):
|
|
self.answers.append(Answer(target, message))
|
|
if self.review.is_started and target == self.channel:
|
|
self.review.add_message(self.nickname, message)
|