forked from mindiell/hebdobot
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import time
|
|
|
|
import irc.bot
|
|
import irc.strings
|
|
|
|
from bot.hebdobot import Hebdobot
|
|
|
|
|
|
class IrcBot(irc.bot.SingleServerIRCBot):
|
|
def __init__(self, settings):
|
|
# Récupération des paramètres
|
|
self.settings = settings
|
|
self.server = self.settings.IRC_SERVER
|
|
self.port = self.settings.IRC_PORT
|
|
self.channel = self.settings.IRC_CHANNEL
|
|
self.nickname = self.settings.IRC_NICK
|
|
self.password = self.settings.IRC_PASSWORD
|
|
|
|
self.bot = Hebdobot(self.settings, self.channel, self.nickname)
|
|
|
|
# Démarrage et connexion à IRC
|
|
irc.bot.SingleServerIRCBot.__init__(
|
|
self, [(self.server, self.port)], self.nickname, self.nickname
|
|
)
|
|
|
|
def on_nicknameinuse(self, connection, event):
|
|
# TODO: Re-tester si son propre nom est disponible plus tard.
|
|
self.nickname = self.nickname + "_"
|
|
self.bot.nickname = self.nickname
|
|
connection.nick(self.nickname)
|
|
|
|
def on_welcome(self, connection, event):
|
|
connection.join(self.channel)
|
|
|
|
def on_privmsg(self, connection, event):
|
|
channel = event.target
|
|
sender = event.source.nick
|
|
message = event.arguments[0]
|
|
answers = self.bot.on_private_message(channel, sender, message)
|
|
for answer in answers:
|
|
self.connection.privmsg(answer.target, answer.message)
|
|
|
|
def on_pubmsg(self, connection, event):
|
|
channel = event.target
|
|
sender = event.source.nick
|
|
message = event.arguments[0]
|
|
answers = self.bot.on_public_message(channel, sender, message)
|
|
for answer in answers:
|
|
self.connection.privmsg(answer.target, answer.message)
|
|
|
|
def send_multiple(self, target, messages):
|
|
for message in messages:
|
|
self.connection.privmsg(target, message)
|
|
time.sleep(self.settings.IRC_DELAY)
|