Fix a bunch of bot code and checkin systemd files

This commit is contained in:
Russell 2018-11-01 11:05:52 -04:00
parent 6770c70068
commit 2a2ed1e064
26 changed files with 222 additions and 137 deletions

View File

@ -0,0 +1,15 @@
[Unit]
Description=banterbot daemon
After=banterbot.service
[Service]
Type=simple
ExecStart=/home/krowbar/Code/irc/banterbot.py -s 127.0.0.1:6667 -n banterbot -c #tildetown #bots
WorkingDirectory=/home/krowbar/Code/irc/
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target

View File

@ -0,0 +1,15 @@
[Unit]
Description=madlibbot daemon
After=madlibbot.service
[Service]
Type=simple
ExecStart=/home/krowbar/Code/irc/madlibbot/madlibbot.py -s 127.0.0.1:6667 -n madlibbot -c #bots #madlibs
WorkingDirectory=/home/krowbar/Code/irc/
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target

View File

@ -0,0 +1,15 @@
[Unit]
Description=tildebot daemon
After=tildebot.service
[Service]
Type=simple
ExecStart=/home/krowbar/Code/irc/tildebot.py -s 127.0.0.1:6667 -n tildebot -c #bots
WorkingDirectory=/home/krowbar/Code/irc/
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target

View File

@ -0,0 +1,15 @@
[Unit]
Description=topicbot daemon
After=topicbot.service
[Service]
Type=simple
ExecStart=/home/krowbar/Code/irc/topicbot.py -s 127.0.0.1:6667 -n topicbot -c #tildetown #bots
WorkingDirectory=/home/krowbar/Code/irc/
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import urllib import urllib
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import random import random
@ -12,7 +13,7 @@ def get_acros(word, silly, short):
url = "http://www.stands4.com/services/v2/abbr.php?uid={}&tokenid={}&term={}".format( url = "http://www.stands4.com/services/v2/abbr.php?uid={}&tokenid={}&term={}".format(
userId, token, word userId, token, word
) )
soup = BeautifulSoup(urllib.urlopen(url).read(), "html5lib") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html5lib")
results = soup.find_all("result") results = soup.find_all("result")
# there are lots of cases where the same definition is repeated multiple times under different categories. this is dumb so we should do a little more work # there are lots of cases where the same definition is repeated multiple times under different categories. this is dumb so we should do a little more work
defs = [] defs = []
@ -60,7 +61,7 @@ def get_acros(word, silly, short):
", ".join(d["categories"]), ", ".join(d["categories"]),
d["score"], d["score"],
) )
).encode("ascii", "ignore") )
) )
if silly is True: if silly is True:
newDef = [] newDef = []
@ -68,11 +69,11 @@ def get_acros(word, silly, short):
try: try:
for idx, letter in enumerate(word): for idx, letter in enumerate(word):
newWord = random.choice( newWord = random.choice(
filter( list(filter(
lambda w: (idx is 0 or not w.strip().lower().endswith("'s")) lambda w: (idx is 0 or not w.strip().lower().endswith("'s"))
and w.lower().startswith(letter.lower()), and w.lower().startswith(letter.lower()),
words, words,
) ))
).strip() ).strip()
print(str(idx) + " -> " + newWord) print(str(idx) + " -> " + newWord)
newDef.append(newWord) newDef.append(newWord)
@ -85,7 +86,7 @@ def get_acros(word, silly, short):
'{}: "{}" ({}, score: {})'.format( '{}: "{}" ({}, score: {})'.format(
word.upper(), newWord, "Tilde.town Original", "0" word.upper(), newWord, "Tilde.town Original", "0"
) )
).encode("ascii", "ignore") )
) )
except IndexError: except IndexError:
acros.append("Future hazy, try again later: Tilde.town Error") acros.append("Future hazy, try again later: Tilde.town Error")

View File

@ -1,11 +1,12 @@
#!/usr/bin/python #!/usr/bin/python3
# using python3 because of unicode and crap
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python # http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries. # Import some necessary libraries.
import argparse
import socket import socket
import os import os
import sys import sys
from optparse import OptionParser
import fileinput import fileinput
import random import random
import re import re
@ -27,9 +28,9 @@ import acronymFinder
import util import util
from whosaid import whoSaid from whosaid import whoSaid
parser = OptionParser() parser = argparse.ArgumentParser()
parser.add_option( parser.add_argument(
"-s", "-s",
"--server", "--server",
dest="server", dest="server",
@ -37,15 +38,16 @@ parser.add_option(
help="the server to connect to", help="the server to connect to",
metavar="SERVER", metavar="SERVER",
) )
parser.add_option( parser.add_argument(
"-c", "-c",
"--channel", "--channels",
dest="channel", dest="channels",
default="#bot_test", nargs="+",
help="the channel to join", default=["#bot_test"],
metavar="CHANNEL", help="the channels to join",
metavar="CHANNELS",
) )
parser.add_option( parser.add_argument(
"-n", "-n",
"--nick", "--nick",
dest="nick", dest="nick",
@ -54,13 +56,14 @@ parser.add_option(
metavar="NICK", metavar="NICK",
) )
(options, args) = parser.parse_args() args = parser.parse_args()
p = inflect.engine() p = inflect.engine()
def joinchan(chan): def joinchan(chan):
ircsock.send("JOIN " + chan + "\r\n") ircsock.send("JOIN " + chan + "\r\n")
ircsock.send("JOIN #bots\r\n")
def hello(): def hello():
@ -122,9 +125,9 @@ def score_banter(channel, user, messageText):
def get_new_banter(channel, user): def get_new_banter(channel, user):
with open("/usr/share/dict/words", "r") as dict: with open("/usr/share/dict/words", "r") as dict:
words = filter(lambda word: re.search(r"^[^']*$", word), dict.readlines()) words = list(filter(lambda word: re.search(r"^[^']*$", word), dict.readlines()))
if random.randint(0, 1): # look for *ant words if random.randint(0, 1): # look for *ant words
words = filter(lambda word: re.search(r"ant", word), words) words = list(filter(lambda word: re.search(r"ant", word), words))
random.shuffle(words) random.shuffle(words)
word = words[0].strip("\n") word = words[0].strip("\n")
start = word.find("ant") start = word.find("ant")
@ -136,7 +139,7 @@ def get_new_banter(channel, user):
else: # replace the letter with 'b' else: # replace the letter with 'b'
word = word[: start - 1] + "b" + word[start:] word = word[: start - 1] + "b" + word[start:]
else: # look for ban* words else: # look for ban* words
words = filter(lambda word: re.search(r"ban", word), words) words = list(filter(lambda word: re.search(r"ban", word), words))
random.shuffle(words) random.shuffle(words)
word = words[0].strip("\n") word = words[0].strip("\n")
end = word.find("ban") + 3 end = word.find("ban") + 3
@ -225,8 +228,6 @@ def get_xkcd(channel, text):
joined_links = ", ".join(links) joined_links = ", ".join(links)
for line in [joined_links[i : i + 400] for i in range(0, len(joined_links), 400)]: for line in [joined_links[i : i + 400] for i in range(0, len(joined_links), 400)]:
util.sendmsg(ircsock, channel, line) util.sendmsg(ircsock, channel, line)
# res = xkcdApropos.xkcd(text[6:])
# ircsock.send("PRIVMSG " + channel + " :" + res + "\n")
def get_wphilosophy(channel, text): def get_wphilosophy(channel, text):
@ -251,7 +252,7 @@ def figlet(channel, text):
else: else:
lines = subprocess.Popen( lines = subprocess.Popen(
["figlet", "-w140"] + text.split(" "), shell=False, stdout=subprocess.PIPE ["figlet", "-w140"] + text.split(" "), shell=False, stdout=subprocess.PIPE
).stdout.read() ).stdout.read().decode("utf-8")
for line in lines.split("\n"): for line in lines.split("\n"):
util.sendmsg(ircsock, channel, line) util.sendmsg(ircsock, channel, line)
time.sleep(0.4) # to avoid channel throttle due to spamming time.sleep(0.4) # to avoid channel throttle due to spamming
@ -265,7 +266,7 @@ def toilet(channel, text):
["toilet", "-w140", "--irc"] + text.split(" "), ["toilet", "-w140", "--irc"] + text.split(" "),
shell=False, shell=False,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
).stdout.read() ).stdout.read().decode("utf-8")
for line in lines.split("\n"): for line in lines.split("\n"):
util.sendmsg(ircsock, channel, line) util.sendmsg(ircsock, channel, line)
time.sleep(0.4) # to avoid channel throttle due to spamming time.sleep(0.4) # to avoid channel throttle due to spamming
@ -277,7 +278,7 @@ def get_acronym(channel, text):
else: else:
defs = acronymFinder.get_acros(text, True, True) defs = acronymFinder.get_acros(text, True, True)
for d in defs[0:5]: # only the first five. they are already sorted by 'score' for d in defs[0:5]: # only the first five. they are already sorted by 'score'
util.sendmsg(ircsock, channel, d.encode("utf-8")) util.sendmsg(ircsock, channel, d)
if len(defs) > 5: if len(defs) > 5:
util.sendmsg(ircsock, channel, defs[-1]) util.sendmsg(ircsock, channel, defs[-1])
@ -337,7 +338,7 @@ def rollcall(channel):
def listen(botnick): def listen(botnick):
while 1: while 1:
ircmsg = ircsock.recv(2048).decode() ircmsg = ircsock.recv(2048).decode('utf-8')
ircmsg = ircmsg.strip("\n\r") ircmsg = ircmsg.strip("\n\r")
if ircmsg[:4] == "PING": if ircmsg[:4] == "PING":
@ -416,5 +417,5 @@ def listen(botnick):
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
util.connect(ircsock, options) util.connect(ircsock, args)
listen(options.nick) listen(args.nick)

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import urllib import urllib
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import random import random
@ -6,11 +7,11 @@ import random
def define(word): def define(word):
defs = [] defs = []
url = "http://www.merriam-webster.com/dictionary/{}".format(word) url = "http://www.merriam-webster.com/dictionary/{}".format(word)
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
head = soup.find("div", id="headword") head = soup.find("div", id="headword")
if head: if head:
for p in head.find_all("p"): for p in head.find_all("p"):
defs.append(p.text.encode("ascii", "ignore")) defs.append(p.text)
return defs return defs
@ -22,11 +23,11 @@ def defWord(word, short=True):
url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/{}?key={}".format( url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/{}?key={}".format(
word, key word, key
) )
soup = BeautifulSoup(urllib.urlopen(url).read(), "html5lib") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html5lib")
entry = soup.find("entry") entry = soup.find("entry")
if entry: if entry:
for d in entry.find_all("dt"): for d in entry.find_all("dt"):
defs.append(d.text.encode("ascii", "ignore")) defs.append(d.text)
if short: if short:
return " ".join(defs) return " ".join(defs)
else: else:

View File

@ -47,7 +47,7 @@ def query(
"d": meanings, "d": meanings,
} }
params.update(kwargs) params.update(kwargs)
encparams = urllib.urlencode(params) encparams = urllib.parse.urlencode(params)
url = "http://api.duckduckgo.com/?" + encparams url = "http://api.duckduckgo.com/?" + encparams
request = requests.get(url, headers={"User-Agent": useragent}) request = requests.get(url, headers={"User-Agent": useragent})

Binary file not shown.

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
import collections import collections
import glob import glob
@ -30,7 +30,7 @@ def find_stories(limit=999, shuffle=False):
files = random.sample(files, max(1, min(limit, len(files)))) files = random.sample(files, max(1, min(limit, len(files))))
else: else:
files = files[:limit] files = files[:limit]
return map(munge_story, files) return list(map(munge_story, files))
# Count the number of replacable words in the story # Count the number of replacable words in the story

View File

@ -1,18 +1,18 @@
#!/usr/bin/python #!/usr/bin/python3
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python # http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries. # Import some necessary libraries.
import socket import socket
import os import os
import sys import sys
from optparse import OptionParser import argparse
import fileinput import fileinput
import random import random
import time import time
import re import re
import operator import operator
from .. import util import util
import madlib import madlib
@ -35,9 +35,9 @@ stories = {} # The list of stories available to users
story = {} # The madlib story currently being worked on story = {} # The madlib story currently being worked on
nextword = {} # The word that the bot is currently expecting data for nextword = {} # The word that the bot is currently expecting data for
parser = OptionParser() parser = argparse.ArgumentParser()
parser.add_option( parser.add_argument(
"-s", "-s",
"--server", "--server",
dest="server", dest="server",
@ -45,15 +45,16 @@ parser.add_option(
help="the server to connect to", help="the server to connect to",
metavar="SERVER", metavar="SERVER",
) )
parser.add_option( parser.add_argument(
"-c", "-c",
"--channel", "--channels",
dest="channel", nargs="+",
default="#madlibs", dest="channels",
help="the channel to join", default=["#madlibs"],
metavar="CHANNEL", help="the channels to join",
metavar="CHANNELS",
) )
parser.add_option( parser.add_argument(
"-n", "-n",
"--nick", "--nick",
dest="nick", dest="nick",
@ -62,7 +63,7 @@ parser.add_option(
metavar="NICK", metavar="NICK",
) )
(options, args) = parser.parse_args() args = parser.parse_args()
def resetGlobals(channel=""): def resetGlobals(channel=""):
@ -88,16 +89,17 @@ def get_stories(channel, botnick):
global stories global stories
state[channel] = State.thinking state[channel] = State.thinking
stories[channel] = madlib.find_stories(MAX_STORIES, True) stories[channel] = madlib.find_stories(MAX_STORIES, True)
if len(stories[channel]) == 0: if len(list(stories[channel])) == 0:
sendmsg(channel, "Uh oh! There are no stories!") util.sendmsg(ircsock, channel, "Uh oh! There are no stories!")
state[channel] = State.idle state[channel] = State.idle
else: else:
sendmsg(channel, "Here are a couple good stories:") util.sendmsg(ircsock, channel, "Here are a couple good stories:")
time.sleep(1 * THROTTLE_FACTOR) time.sleep(1 * THROTTLE_FACTOR)
for idx, story in enumerate(stories[channel]): for idx, story in enumerate(stories[channel]):
sendmsg(channel, "[{}] {} ({} words)".format(idx, story[0], story[2])) util.sendmsg(ircsock, channel, "[{}] {} ({} words)".format(idx, story[0], story[2]))
time.sleep(0.5 * THROTTLE_FACTOR) time.sleep(0.5 * THROTTLE_FACTOR)
sendmsg( util.sendmsg(
ircsock,
channel, channel,
"Please select a story by index by saying '{}: <number>':".format(botnick), "Please select a story by index by saying '{}: <number>':".format(botnick),
) )
@ -132,7 +134,7 @@ def handle_bot_msg(channel, msg, botnick):
# Handle how to quit the game # Handle how to quit the game
def quit_game(channel): def quit_game(channel):
resetGlobals(channel) resetGlobals(channel)
sendmsg(channel, "Ok, quitting the current game.") util.sendmsg(ircsock, channel, "Ok, quitting the current game.")
# Handle user input when we are in story selection mode # Handle user input when we are in story selection mode
@ -141,12 +143,12 @@ def handle_story_selection(channel, msg, botnick):
global state global state
try: try:
imsg = int(msg) imsg = int(msg)
if imsg < 0 or imsg > len(stories[channel]): if imsg < 0 or imsg > len(list(stories[channel])):
sendmsg(channel, "Selection out of bounds. Try again!") util.sendmsg(ircsock, channel, "Selection out of bounds. Try again!")
return return
time.sleep(1 * THROTTLE_FACTOR) time.sleep(1 * THROTTLE_FACTOR)
sendmsg( util.sendmsg(
channel, "Give me a second to load up {}".format(stories[channel][imsg][0]) ircsock, channel, "Give me a second to load up {}".format(stories[channel][imsg][0])
) )
with open(stories[channel][imsg][1], "r") as storyFile: with open(stories[channel][imsg][1], "r") as storyFile:
@ -154,7 +156,7 @@ def handle_story_selection(channel, msg, botnick):
stories[channel] = {} # Clear out the saved selectable stories in memory stories[channel] = {} # Clear out the saved selectable stories in memory
story_start(channel, botnick) story_start(channel, botnick)
except ValueError: except ValueError:
sendmsg(channel, "Invalid selection. Try again!") util.sendmsg(ircsock, channel, "Invalid selection. Try again!")
state[channel] = State.story_selection state[channel] = State.story_selection
@ -165,7 +167,8 @@ def story_start(channel, botnick):
global nextword global nextword
state[channel] = State.thinking state[channel] = State.thinking
sendmsg( util.sendmsg(
ircsock,
channel, channel,
"Alright! Let's get started! Say '{}: <word>' to give me words.".format( "Alright! Let's get started! Say '{}: <word>' to give me words.".format(
botnick botnick
@ -173,7 +176,7 @@ def story_start(channel, botnick):
) )
nextword[channel] = madlib.find_next_word(story[channel], True) nextword[channel] = madlib.find_next_word(story[channel], True)
time.sleep(0.5 * THROTTLE_FACTOR) time.sleep(0.5 * THROTTLE_FACTOR)
sendmsg(channel, "Give me {}:".format(nextword[channel][1])) util.sendmsg(ircsock, channel, "Give me {}:".format(nextword[channel][1]))
state[channel] = State.word_input state[channel] = State.word_input
@ -196,7 +199,8 @@ def handle_story_step(channel, msg):
return return
# else # else
count = madlib.count_words(story[channel]) count = madlib.count_words(story[channel])
sendmsg( util.sendmsg(
ircsock,
channel, channel,
"Thanks! Now give me {} ({} words left)".format(nextword[channel][1], count), "Thanks! Now give me {} ({} words left)".format(nextword[channel][1], count),
) )
@ -208,15 +212,15 @@ def finish_story(channel):
global state global state
global story global story
sendmsg(channel, "Ok, here's the story...") util.sendmsg(ircsock, channel, "Ok, here's the story...")
sendmsg(channel, "=" * MAX_LINE) util.sendmsg(ircsock, channel, "=" * MAX_LINE)
for line in story[channel].splitlines(): for line in story[channel].splitlines():
for part in madlib.yield_lines(line, MAX_LINE): for part in madlib.yield_lines(line, MAX_LINE):
time.sleep(0.6 * THROTTLE_FACTOR) time.sleep(0.6 * THROTTLE_FACTOR)
sendmsg(channel, part) util.sendmsg(ircsock, channel, part)
padlen = (MAX_LINE - 9) / 2 padlen = int((MAX_LINE - 9) / 2)
mod = (MAX_LINE - 9) % 2 mod = (MAX_LINE - 9) % 2
sendmsg(channel, "=" * padlen + " THE END " + "=" * (padlen + mod)) util.sendmsg(ircsock, channel, "=" * padlen + " THE END " + "=" * (padlen + mod))
story[channel] = "" story[channel] = ""
state[channel] = State.idle state[channel] = State.idle
@ -235,14 +239,16 @@ def rollcall(channel, botnick):
state[channel] = State.idle state[channel] = State.idle
if state[channel] == State.idle: if state[channel] == State.idle:
sendmsg( util.sendmsg(
ircsock,
channel, channel,
"Do you like MadLibs? Start a collaborative story by saying '{}: startgame'".format( "Do you like MadLibs? Start a collaborative story by saying '{}: startgame'".format(
botnick botnick
), ),
) )
else: else:
sendmsg( util.sendmsg(
ircsock,
channel, channel,
"A game is already in progress. Say '{}: <word>' to provide me with the next word or '{}: !quit' to stop the current game".format( "A game is already in progress. Say '{}: <word>' to provide me with the next word or '{}: !quit' to stop the current game".format(
botnick, botnick botnick, botnick
@ -255,11 +261,11 @@ def listen(botnick):
"^{}\:?\s*(.*)$".format(botnick) "^{}\:?\s*(.*)$".format(botnick)
) # re to strip the bot's name from a message ) # re to strip the bot's name from a message
while 1: while 1:
ircmsg = ircsock.recv(2048) ircmsg = ircsock.recv(2048).decode("utf-8")
ircmsg = ircmsg.strip("\n\r") ircmsg = ircmsg.strip("\n\r")
if ircmsg[:4] == "PING": if ircmsg[:4] == "PING":
ping(ircmsg.split(" ")[1]) util.ping(ircsock, ircmsg)
formatted = util.format_message(ircmsg) formatted = util.format_message(ircmsg)
if "" == formatted: if "" == formatted:
@ -287,5 +293,5 @@ def listen(botnick):
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
util.connect(ircsock, options) util.connect(ircsock, args)
listen(options.nick) listen(args.nick)

View File

@ -77,7 +77,7 @@ def say_chatty(channel):
def listen(): def listen():
while 1: while 1:
ircmsg = ircsock.recv(2048).decode() ircmsg = ircsock.recv(2048).decode("utf-8")
ircmsg = ircmsg.strip("\r\n") ircmsg = ircmsg.strip("\r\n")
formatted = util.format_message(ircmsg) formatted = util.format_message(ircmsg)

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import urllib import urllib
# from lxml.html import fromstring # from lxml.html import fromstring
@ -8,7 +9,7 @@ import random
def getRhymes(word): def getRhymes(word):
words = [] words = []
url = "http://www.rhymer.com/RhymingDictionaryLast/%s.html" % word url = "http://www.rhymer.com/RhymingDictionaryLast/%s.html" % word
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
for t in soup.find_all("table", "table"): for t in soup.find_all("table", "table"):
words.append( words.append(
@ -29,11 +30,11 @@ def rhymeZone(word):
"http://rhymezone.com/r/rhyme.cgi?Word=%s&typeofrhyme=perfect&org1=syl&org2=l&org3=y" "http://rhymezone.com/r/rhyme.cgi?Word=%s&typeofrhyme=perfect&org1=syl&org2=l&org3=y"
% word % word
) )
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
for t in soup.find_all("a", "d"): for t in soup.find_all("a", "d"):
w = t.text.rstrip() w = t.text.rstrip()
if w not in [u"", u"\xa0"] and "?" not in t: if w not in [u"", u"\xa0"] and "?" not in t:
words.append(w.encode("ascii", "ignore")) words.append(w)
random.shuffle(words) random.shuffle(words)
return words[0:5] return words[0:5]

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
if [[ ! `pidof -sx banterbot.py` ]]; then if [[ ! `pidof -sx banterbot.py` ]]; then
nohup ./banterbot.py -s 127.0.0.1 -n banterbot -c \#tildetown >> banterlog 2>> banterlog & #nohup ./banterbot.py -s 127.0.0.1:6667 -n banterbot -c \#tildetown \#bots >> banterlog 2>> banterlog &
echo "Starting banterbot" echo "Starting banterbot"
#nohup ./banterbot.py -s 127.0.0.1 -n banterbot -c \#bot_test >> banterlog 2>> banterlog & nohup ./banterbot.py -s 127.0.0.1:6667 -n banterbot -c \#bots >> banterlog 2>> banterlog &
else else
echo "Banterbot has already been started" echo "Banterbot has already been started"
fi fi

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
if [[ ! `pidof -sx madlibbot.py` ]]; then if [[ ! `pidof -sx madlibbot.py` ]]; then
nohup ./madlibbot/madlibbot.py -s 127.0.0.1 -n madlibbot -c \#bots >> madliblog 2>> madliblog & nohup ./madlibbot/madlibbot.py -s 127.0.0.1:6667 -n madlibbot -c \#bots \#madlibs >> madliblog 2>> madliblog &
echo "Starting madlibbot" echo "Starting madlibbot"
else else
echo "madlibbot has already been started" echo "madlibbot has already been started"

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
if [[ ! `pidof -sx tildebot.py` ]]; then if [[ ! `pidof -sx tildebot.py` ]]; then
nohup ./tildebot.py -s 127.0.0.1 -n tildebot -c \#tildetown >> tildelog 2>> tildelog & echo "Starting tildebot"
nohup ./tildebot.py -s 127.0.0.1:6667 -n tildebot -c \#tildetown \#bots >> tildelog 2>> tildelog &
#nohup ./tildebot.py -s 127.0.0.1:6667 -n tildebot -c \#bots >> tildelog 2>> tildelog &
else
echo "Tildebot has already been started"
fi fi
#nohup ./tildebot.py -s 127.0.0.1 -n tildebot -c \#bot_test >> tildelog 2>> tildelog &

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
if [[ ! `pidof -sx topicbot.py` ]]; then if [[ ! `pidof -sx topicbot.py` ]]; then
nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#tildetown >> topiclog 2>> log & nohup ./topicbot.py -s 127.0.0.1:6667 -n topicbot -c \#tildetown \#bots >> topiclog 2>> topiclog &
fi fi
#nohup ./topicbot.py -s 127.0.0.1 -n topicbot -c \#bot_test >> topiclog 2>> log & #nohup ./topicbot.py -s 127.0.0.1:6667 -n topicbot -c \#bot_test \#bots >> topiclog 2>> topiclog &
#./topic_bot.py -s 127.0.0.1 -n topic_bot -c \#bot_test #./topic_bot.py -s 127.0.0.1 -n topic_bot -c \#bot_test

View File

@ -6,7 +6,7 @@ import socket
import os import os
import sys import sys
import time import time
from optparse import OptionParser import argparse
import fileinput import fileinput
import random import random
@ -14,9 +14,9 @@ import inflect
import puzzle import puzzle
import util import util
parser = OptionParser() parser = argparse.ArgumentParser()
parser.add_option( parser.add_argument(
"-s", "-s",
"--server", "--server",
dest="server", dest="server",
@ -24,15 +24,16 @@ parser.add_option(
help="the server to connect to", help="the server to connect to",
metavar="SERVER", metavar="SERVER",
) )
parser.add_option( parser.add_argument(
"-c", "-c",
"--channel", "--channels",
dest="channel", dest="channels",
default="#bot_test", nargs="+",
help="the channel to join", default=["#bot_test"],
metavar="CHANNEL", help="the channels to join",
metavar="CHANNELS",
) )
parser.add_option( parser.add_argument(
"-n", "-n",
"--nick", "--nick",
dest="nick", dest="nick",
@ -41,7 +42,7 @@ parser.add_option(
metavar="NICK", metavar="NICK",
) )
(options, args) = parser.parse_args() args = parser.parse_args()
p = inflect.engine() p = inflect.engine()
challenges = {} challenges = {}
@ -325,7 +326,7 @@ def rollcall(channel):
def listen(): def listen():
while 1: while 1:
ircmsg = ircsock.recv(2048).decode() ircmsg = ircsock.recv(2048).decode("utf-8")
for msg in ircmsg.split("\n"): for msg in ircmsg.split("\n"):
msg = msg.strip("\n\r") msg = msg.strip("\n\r")
@ -334,7 +335,7 @@ def listen():
continue continue
formatted = util.format_message(msg) formatted = util.format_message(msg)
print(formatted) # print(formatted)
if "" == formatted: if "" == formatted:
continue continue
@ -360,5 +361,5 @@ def listen():
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
util.connect(ircsock, options) util.connect(ircsock, args)
listen() listen()

View File

@ -1,4 +1,4 @@
krowbar&^%2430&^%1540473099 krowbar&^%2507&^%1541083807
karlen&^%498&^%1527613440 karlen&^%498&^%1527613440
endorphant&^%682&^%1444775660 endorphant&^%682&^%1444775660
jumblesale&^%24&^%1426171214 jumblesale&^%24&^%1426171214
@ -55,11 +55,11 @@ tybaltcat&^%7&^%1481076625
minerbot&^%146&^%1520382015 minerbot&^%146&^%1520382015
mio&^%347&^%1529720473 mio&^%347&^%1529720473
archangel&^%479&^%1538689239 archangel&^%479&^%1538689239
tehfraga&^%656&^%1540457107 tehfraga&^%669&^%1540933836
sushi&^%10&^%1493253212 sushi&^%10&^%1493253212
troido&^%302&^%1538991819 troido&^%302&^%1538991819
gamebot&^%199&^%1538991833 gamebot&^%199&^%1538991833
nilaky&^%1406&^%1540432090 nilaky&^%1445&^%1541047850
bucket&^%103&^%1507931139 bucket&^%103&^%1507931139
lolbot&^%1&^%1502568407 lolbot&^%1&^%1502568407
m455&^%12&^%1512076715 m455&^%12&^%1512076715
@ -73,7 +73,7 @@ emfor&^%3&^%1509671353
k2l8m11n2&^%11&^%1510932395 k2l8m11n2&^%11&^%1510932395
sacredpix&^%3&^%1522082931 sacredpix&^%3&^%1522082931
deltawitc&^%3267&^%1538609961 deltawitc&^%3267&^%1538609961
login&^%2395&^%1540411798 login&^%2446&^%1541083668
kelpiebot&^%3&^%1513101957 kelpiebot&^%3&^%1513101957
unreal&^%2&^%1534387108 unreal&^%2&^%1534387108
tildethie&^%5612&^%1538710812 tildethie&^%5612&^%1538710812
@ -93,7 +93,7 @@ saturn597&^%3&^%1521429369
cwmccabe&^%2&^%1521598124 cwmccabe&^%2&^%1521598124
lucidiot&^%28&^%1526201925 lucidiot&^%28&^%1526201925
tracer&^%1&^%1521744878 tracer&^%1&^%1521744878
jan6&^%1087&^%1540323640 jan6&^%1088&^%1540831048
jan&^%10&^%1522319160 jan&^%10&^%1522319160
etathetae&^%3&^%1522937843 etathetae&^%3&^%1522937843
eeeeeta&^%52&^%1540361066 eeeeeta&^%52&^%1540361066
@ -106,15 +106,15 @@ Halian&^%32&^%1528360263
lunasspec&^%4&^%1524164784 lunasspec&^%4&^%1524164784
bowlercap&^%3&^%1524165068 bowlercap&^%3&^%1524165068
littlebig&^%46&^%1535927253 littlebig&^%46&^%1535927253
severak&^%16&^%1533802439 severak&^%17&^%1540822455
ralph&^%4&^%1526980620 ralph&^%4&^%1526980620
benjaminw&^%526&^%1538599664 benjaminw&^%526&^%1538599664
von&^%404&^%1540199114 von&^%407&^%1540980176
ensis&^%1750&^%1539356542 ensis&^%1750&^%1539356542
simon&^%26&^%1527937489 simon&^%26&^%1527937489
benharri&^%1962&^%1540473154 benharri&^%2055&^%1541052332
cpb&^%3&^%1528930564 cpb&^%3&^%1528930564
calmbit&^%150&^%1537918704 calmbit&^%156&^%1540942599
wisebot&^%5613&^%1539612163 wisebot&^%5613&^%1539612163
paannd_a&^%2&^%1529617165 paannd_a&^%2&^%1529617165
nincollin&^%6&^%1531186900 nincollin&^%6&^%1531186900
@ -123,20 +123,22 @@ pounce&^%19&^%1532133325
von_&^%5&^%1532502104 von_&^%5&^%1532502104
livix&^%7&^%1533603142 livix&^%7&^%1533603142
ben&^%3&^%1533767627 ben&^%3&^%1533767627
npa&^%78&^%1536235183 npa&^%84&^%1541066354
ezo&^%6&^%1533883842 ezo&^%6&^%1533883842
aliasless&^%31&^%1539879035 aliasless&^%36&^%1541001821
kirch&^%41&^%1535571833 kirch&^%51&^%1541006239
root&^%2&^%1535558514 root&^%2&^%1535558514
byte&^%5&^%1536416308 byte&^%5&^%1536416308
qbe&^%7&^%1537850181 qbe&^%7&^%1537850181
informati&^%3&^%1536733938 informati&^%3&^%1536733938
h00fi&^%1&^%1537050053 h00fi&^%1&^%1537050053
fantoro&^%4&^%1540021663 fantoro&^%7&^%1540854244
tildethief&^%783&^%1540475833 tildethief&^%1051&^%1541084586
benjaminwil&^%7&^%1539378917 benjaminwil&^%9&^%1541018886
deltawitch&^%11&^%1539184112 deltawitch&^%12&^%1540915500
archangelic&^%1&^%1540407712 archangelic&^%2&^%1540574433
diodelass&^%3&^%1539382302 diodelass&^%3&^%1539382302
minerobber&^%4&^%1540467667 minerobber&^%4&^%1540467667
brendantcc&^%3&^%1539908223 brendantcc&^%3&^%1539908223
dozens&^%16&^%1540784558
bowlercaptain&^%3&^%1540926135

View File

@ -1,21 +1,21 @@
#!/usr/bin/python #!/usr/bin/python3
# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python # http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python
# Import some necessary libraries. # Import some necessary libraries.
import socket import socket
import os import os
import sys import sys
from optparse import OptionParser
import fileinput import fileinput
import random import random
import time import time
import argparse
import inflect import inflect
import util import util
parser = OptionParser() parser = argparse.ArgumentParser()
parser.add_option( parser.add_argument(
"-s", "-s",
"--server", "--server",
dest="server", dest="server",
@ -23,15 +23,16 @@ parser.add_option(
help="the server to connect to", help="the server to connect to",
metavar="SERVER", metavar="SERVER",
) )
parser.add_option( parser.add_argument(
"-c", "-c",
"--channel", "--channels",
dest="channel", dest="channels",
default="#bot_test", nargs="+",
help="the channel to join", default=["#bot_test"],
metavar="CHANNEL", help="the channels to join",
metavar="CHANNELS",
) )
parser.add_option( parser.add_argument(
"-n", "-n",
"--nick", "--nick",
dest="nick", dest="nick",
@ -40,7 +41,7 @@ parser.add_option(
metavar="NICK", metavar="NICK",
) )
(options, args) = parser.parse_args() args = parser.parse_args()
p = inflect.engine() p = inflect.engine()
@ -162,7 +163,7 @@ def topic_history(channel, user, count):
def listen(): def listen():
while 1: while 1:
ircmsg = ircsock.recv(2048).decode() ircmsg = ircsock.recv(2048).decode("utf-8")
ircmsg = ircmsg.strip("\n\r") ircmsg = ircmsg.strip("\n\r")
if ircmsg[:4] == "PING": if ircmsg[:4] == "PING":
@ -177,7 +178,7 @@ def listen():
msgtime, user, command, channel, messageText = formatted.split("\t") msgtime, user, command, channel, messageText = formatted.split("\t")
if command == "TOPIC" and user != options.nick: if command == "TOPIC" and user != args.nick:
count_topic(channel, user, msgtime, messageText) count_topic(channel, user, msgtime, messageText)
if ircmsg.find(":!topic") != -1: if ircmsg.find(":!topic") != -1:
@ -207,5 +208,5 @@ def listen():
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
util.connect(ircsock, options) util.connect(ircsock, args)
listen() listen()

View File

@ -1,2 +1,2 @@
vilmibm&^%0&^%4 vilmibm&^%0&^%4
krowbar&^%0&^%1vantablack&^%1&^%0 krowbar&^%2&^%1vantablack

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import urllib import urllib
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import random import random
@ -6,7 +7,7 @@ import re
def tumble(url): def tumble(url):
# Find the max pages # Find the max pages
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser") soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
pages = soup.findAll("span", "page-numbers")[0].text.split("/")[ pages = soup.findAll("span", "page-numbers")[0].text.split("/")[
1 1
] # this could totally fail several ways ] # this could totally fail several ways
@ -17,7 +18,7 @@ def tumble(url):
# Parse a page # Parse a page
soup = BeautifulSoup( soup = BeautifulSoup(
urllib.urlopen(url + "/page/" + str(page)).read(), "html.parser" urllib.request.urlopen(url + "/page/" + str(page)).read(), "html.parser"
) )
article = random.choice(soup.findAll("article")) article = random.choice(soup.findAll("article"))
quote = article.find("blockquote").text.replace("\n", "") quote = article.find("blockquote").text.replace("\n", "")

View File

@ -41,6 +41,10 @@ def connect(ircsock, options):
mode = "MODE +B {}\r\n".format(options.nick).encode() mode = "MODE +B {}\r\n".format(options.nick).encode()
print(mode) print(mode)
ircsock.send(mode) ircsock.send(mode)
if 'channels' in options:
for channel in options.channels:
joinchan(ircsock, channel)
else:
joinchan(ircsock, options.channel) joinchan(ircsock, options.channel)

View File

@ -281,7 +281,7 @@ def rollcall(channel):
def listen(): def listen():
while 1: while 1:
ircmsg = ircsock.recv(2048).decode() ircmsg = ircsock.recv(2048).decode("utf-8")
ircmsg = ircmsg.strip("\n\r") ircmsg = ircmsg.strip("\n\r")
if ircmsg[:4] == "PING": if ircmsg[:4] == "PING":

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import duckduckgo import duckduckgo
import urllib import urllib
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -10,7 +11,7 @@ def xkcd(query):
title = BeautifulSoup(urllib.urlopen(res).read(), "html.parser").title.text title = BeautifulSoup(urllib.urlopen(res).read(), "html.parser").title.text
except: except:
pass # just swallow the error. maybe the result wasn't a url or something else bad happened pass # just swallow the error. maybe the result wasn't a url or something else bad happened
return [(((title + " - ") if title else "") + res).encode("ascii", "ignore")] return [(((title + " - ") if title else "") + res)]
# never mind, blocked by ddg # never mind, blocked by ddg
@ -19,7 +20,8 @@ def xkcd(query):
# soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser') # soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
# items = soup.find_all("a", class_="result__a") # items = soup.find_all("a", class_="result__a")
# print items # print items
# items = filter(lambda i: i[0:8] == 'xkcd.com', [i.find(class_="result__title").text.strip() for i in items]) # items = list(filter(lambda i: i[0:8] == 'xkcd.com',
# [i.find(class_="result__title").text.strip() for i in items]))
# print items # print items
# def pretty_link(item): # def pretty_link(item):
# url = item.find(class_="result__url").text.strip() # url = item.find(class_="result__url").text.strip()

View File

@ -13,6 +13,7 @@
<div> <div>
<select id="series"> <select id="series">
<option value="">Today</option> <option value="">Today</option>
<option value="_2018_10">Oct 2018</option>
<option value="_2018_09">Sep 2018</option> <option value="_2018_09">Sep 2018</option>
<option value="_2018_08">Aug 2018</option> <option value="_2018_08">Aug 2018</option>
<option value="_2018_07">Jul 2018</option> <option value="_2018_07">Jul 2018</option>