Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions asciis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@
"MUSHROOOOO+M",
"[Ii] propose"] # please keep this last

def equal_thirds(size):
if(size % 3 == 2):
return int(size/3)+1
else:
return int(size/3)

def load(filename):
lines = [x.decode('utf8').rstrip() for x in open(filename).readlines()]
third = len(lines)/3
lines = [x.rstrip() for x in open(filename).readlines()]
third = equal_thirds(len(lines))
return [ lines[0:third], lines[third:2*third], lines[2*third:] ]

asciis=[
Expand Down
10 changes: 4 additions & 6 deletions trainbotbrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import time
import urllib
import asciis
from trainbotpass import ownernick

botnicks = ["tra1n", "tra2n", "tra3n"]

from importlib import reload
from trainbotpass import ownernick, botnicks

class trainbot(object):
def __init__(self):
Expand All @@ -38,7 +36,7 @@ def amsearch(self, c, name, channel, query):
trips = self.amscrape(match.group(1), match.group(2), match.group(3))
except Exception as inst:
c.privmsg(channel, "amtrak search failed")
print "amtrak oops: " + str(inst)
print("amtrak oops: ", str(inst))
return
if trips:
c.privmsg(channel, "depart duration arrive price")
Expand All @@ -57,7 +55,7 @@ def mbsearch(self, c, name, channel, query):

except Exception as inst:
c.privmsg(channel, "megabus search failed")
print "megabus oops: " + str(inst)
print("megabus oops: ", str(inst))
return
if trips:
c.privmsg(channel, "depart arrive price")
Expand Down
22 changes: 11 additions & 11 deletions trainbotrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@

import irc.client
import irc.bot
import ib3.auth
import ib3.connection
import sys
import time
from importlib import reload
from threading import Thread
import trainbotbrain
from trainbotpass import password, ownernick
from trainbotpass import password, ownernick, botnicks

channel = sys.argv[1]

irc.client.ServerConnection.buffer_class.errors = 'replace'

class reloader(irc.bot.SingleServerIRCBot):
class reloader(ib3.auth.SASL, ib3.connection.SSL, irc.bot.SingleServerIRCBot):
def __init__(self, serverspec, nick, bots):
irc.bot.SingleServerIRCBot.__init__(self, serverspec, nick, nick)
ib3.auth.SASL.__init__(self, serverspec, nick, nick, password, [channel])
self.nick = nick
self.bots = bots
self.botclassname = nick + "bot"
self.botclassname = "tra"+str(botnicks.index(nick)+1)+"nbot"
self.brain = getattr(trainbotbrain, self.botclassname)()
self.broken = False

def on_welcome(self, c, event):
print c.nickname , "is now online"
c.privmsg("nickserv", "identify " + password)
c.join(channel)
print(c.nickname , "is now online")

def on_pubmsg(self, c, event):
if not self.broken:
Expand All @@ -42,10 +44,10 @@ def on_privmsg(self, c, event):
self.broken = False
except Exception as thisbroke:
self.errorhandle(thisbroke, c)
elif event.source.nick == ownernick and event.arguments[0].split(' ')[0] == "reset":
elif event.source.nick == ownernick and event.arguments[0].split(' ')[0] == "reset":
nicktoreset = event.arguments[0].split(' ')[1]
self.bots[nicktoreset].stop_bot()
newbot = run_trainbot("irc.freenode.net", 6667, nicktoreset, bots)
newbot = run_trainbot("irc.libera.chat", 6697, nicktoreset, bots)
self.bots[nicktoreset] = newbot
newbot.start()
elif not self.broken:
Expand All @@ -59,7 +61,6 @@ def errorhandle(self, thisbroke, c):
print ("%s had an error of type %s: %s" % (self.nick, type(thisbroke), thisbroke))
self.broken = True


class run_trainbot(Thread):
def __init__(self, server, port, nick, bots):
self.serverspec = [(server, port)]
Expand All @@ -75,10 +76,9 @@ def stop_bot(self):
self.bot.disconnect()
self.bot.connection.close()

botnicks = ["tra1n", "tra2n", "tra3n"]
bots = {}
for nick in botnicks:
bot = run_trainbot("irc.freenode.net", 6667, nick, bots)
bot = run_trainbot("irc.libera.chat", 6697, nick, bots)
bot.daemon = True
bots[nick] = bot
bot.start()
Expand Down