Compare commits

..

No commits in common. "4ee71a6d4abe75515cd242739ec632cff4e7741b" and "fb85f170a9ffb30f95c003e03927696e68e988ad" have entirely different histories.

4 changed files with 17 additions and 28 deletions

2
README
View File

@ -13,6 +13,8 @@ trusted.txt: People that have access to #op and friends. Format is
sensitive.
gods.txt: Same as above, except can't be #untrust'ed
msgs.txt: Messages that haven't been delivered. Leave it empty
startcmd.txt: Raw IRC messages to send to the server after USER and NICK. Used
to authenticate with NickServ
bot.conf: See bot.conf.example
Run `python3 ircbot.py`

View File

@ -5,7 +5,3 @@ nick = oonbotti2
username = oonbotti2
realname = oonbotti2
channels = ##ingsoc
[auth]
user = oonbotti2
password = nicetryofficer

View File

@ -13,7 +13,10 @@ def initialize(*, config):
# Blocks the bot until it's done, including PING/PONG handling
# irc is the IRC API object
def on_connect(*, irc):
pass
with open('startcmd.txt', 'r') as f:
for i in f:
while i[-1:] == '\n': i = i[:-1]
irc.send_raw(i.encode())
# on_quit(*, irc)
# Called just before IRC bot sends QUIT

View File

@ -142,12 +142,11 @@ class API:
self.serverthread_object.logging_channel.send((logmessage_types.internal, internal_submessage_types.error, message))
# ServerThread(server, auth, control_channel, cron_control_channel, logging_channel)
# ServerThread(server, control_channel, cron_control_channel, logging_channel)
# Creates a new server main loop thread
class ServerThread(threading.Thread):
def __init__(self, server, auth, control_channel, cron_control_channel, logging_channel):
def __init__(self, server, control_channel, cron_control_channel, logging_channel):
self.server = server
self.auth = auth
self.control_channel = control_channel
self.cron_control_channel = cron_control_channel
self.logging_channel = logging_channel
@ -331,16 +330,11 @@ class ServerThread(threading.Thread):
try:
# Run initialization
# Use server-password based authentication if it's set up
user, password = self.auth
if user is not None:
self.send_line_raw(b'PASS %s:%s' % (user.encode(), password.encode()))
# Set up nick and username
self.api.nick(self.server.nick.encode('utf-8'))
self.send_line_raw(b'USER %s a a :%s' % (self.server.username.encode('utf-8'), self.server.realname.encode('utf-8')))
# Set up nick
self.api.nick(self.server.nick.encode('utf-8'))
# Run the on_connect hook, to allow further setup
botcmd.on_connect(irc = self.api)
@ -383,12 +377,12 @@ class ServerThread(threading.Thread):
# Tell cron we're quiting
cron.quit(cron_control_channel)
# spawn_serverthread(server, auth, cron_control_channel, logging_channel) → control_channel
# spawn_serverthread(server, cron_control_channel, logging_channel) → control_channel
# Creates a ServerThread for given server and returns the channel for controlling it
def spawn_serverthread(server, auth, cron_control_channel, logging_channel):
def spawn_serverthread(server, cron_control_channel, logging_channel):
thread_control_socket, spawner_control_socket = socket.socketpair()
control_channel = channel.Channel()
ServerThread(server, auth, control_channel, cron_control_channel, logging_channel).start()
ServerThread(server, control_channel, cron_control_channel, logging_channel).start()
return control_channel
# spawn_loggerthread() → logging_channel, dead_notify_channel
@ -412,24 +406,18 @@ def read_config():
realname = config['server']['realname']
channels = config['server']['channels'].split()
user = None
password = None
if 'auth' in config:
user = config['auth']['user']
password = config['auth']['password']
server = Server(host = host, port = port, nick = nick, username = username, realname = realname, channels = channels)
return config, server, (user, password)
return config, server
if __name__ == '__main__':
config, server, auth = read_config()
config, server = read_config()
botcmd.initialize(config = config)
cron_control_channel = cron.start()
logging_channel, dead_notify_channel = spawn_loggerthread()
control_channel = spawn_serverthread(server, auth, cron_control_channel, logging_channel)
control_channel = spawn_serverthread(server, cron_control_channel, logging_channel)
while True:
message = dead_notify_channel.recv(blocking = False)