hebdobot/ircbot.py

35 lines
1.0 KiB
Python
Raw Normal View History

2024-01-11 08:17:25 +01:00
import time
import irc.bot
class IrcBot(irc.bot.SingleServerIRCBot):
def __init__(self, settings):
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
# Starting Bot
2024-01-11 08:17:25 +01:00
irc.bot.SingleServerIRCBot.__init__(
self, [(self.server, self.port)], self.nickname, self.nickname
)
def on_nicknameinuse(self, connection, event):
# TODO: Check again if name is available later
2024-01-11 08:17:25 +01:00
self.nickname = self.nickname + "_"
connection.nick(self.nickname)
def on_welcome(self, connection, event):
connection.join(self.channel)
def send(self, target, message):
self.connection.privmsg(target, message)
2024-01-11 08:17:25 +01:00
def send_multiple(self, target, messages):
for message in messages:
self.send(target, message)
2024-01-11 08:17:25 +01:00
time.sleep(self.settings.IRC_DELAY)