From 2a2ed1e0649f470f931a517cfb7a996aab17075c Mon Sep 17 00:00:00 2001 From: Russell Date: Thu, 1 Nov 2018 11:05:52 -0400 Subject: [PATCH] Fix a bunch of bot code and checkin systemd files --- .config/systemd/user/banterbot.service | 15 +++++ .config/systemd/user/madlibbot.service | 15 +++++ .config/systemd/user/tildebot.service | 15 +++++ .config/systemd/user/topicbot.service | 15 +++++ Code/irc/acronymFinder.py | 11 ++-- Code/irc/banterbot.py | 47 +++++++------- Code/irc/defineWord.py | 9 +-- Code/irc/duckduckgo.py | 2 +- Code/irc/inflect.pyc | Bin 83694 -> 85210 bytes Code/irc/madlibbot/madlib.py | 4 +- Code/irc/madlibbot/madlibbot.py | 82 +++++++++++++------------ Code/irc/quote_bot.py | 2 +- Code/irc/rhymesWith.py | 7 ++- Code/irc/run_banter.sh | 4 +- Code/irc/run_madlib.sh | 2 +- Code/irc/run_tilde.sh | 7 ++- Code/irc/run_topic.sh | 4 +- Code/irc/tildebot.py | 29 ++++----- Code/irc/tildescores.txt | 36 ++++++----- Code/irc/topicbot.py | 31 +++++----- Code/irc/topicscores.txt | 2 +- Code/irc/tumblr.py | 5 +- Code/irc/util.py | 6 +- Code/irc/wangbot.py | 2 +- Code/irc/xkcdApropos.py | 6 +- public_html/chatcloud/index.html | 1 + 26 files changed, 222 insertions(+), 137 deletions(-) create mode 100755 .config/systemd/user/banterbot.service create mode 100755 .config/systemd/user/madlibbot.service create mode 100755 .config/systemd/user/tildebot.service create mode 100755 .config/systemd/user/topicbot.service diff --git a/.config/systemd/user/banterbot.service b/.config/systemd/user/banterbot.service new file mode 100755 index 0000000..9e7b671 --- /dev/null +++ b/.config/systemd/user/banterbot.service @@ -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 diff --git a/.config/systemd/user/madlibbot.service b/.config/systemd/user/madlibbot.service new file mode 100755 index 0000000..4a5291d --- /dev/null +++ b/.config/systemd/user/madlibbot.service @@ -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 diff --git a/.config/systemd/user/tildebot.service b/.config/systemd/user/tildebot.service new file mode 100755 index 0000000..f16f0da --- /dev/null +++ b/.config/systemd/user/tildebot.service @@ -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 diff --git a/.config/systemd/user/topicbot.service b/.config/systemd/user/topicbot.service new file mode 100755 index 0000000..99c5784 --- /dev/null +++ b/.config/systemd/user/topicbot.service @@ -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 diff --git a/Code/irc/acronymFinder.py b/Code/irc/acronymFinder.py index 9f018d3..1b83c92 100644 --- a/Code/irc/acronymFinder.py +++ b/Code/irc/acronymFinder.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import urllib from bs4 import BeautifulSoup 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( userId, token, word ) - soup = BeautifulSoup(urllib.urlopen(url).read(), "html5lib") + soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html5lib") 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 defs = [] @@ -60,7 +61,7 @@ def get_acros(word, silly, short): ", ".join(d["categories"]), d["score"], ) - ).encode("ascii", "ignore") + ) ) if silly is True: newDef = [] @@ -68,11 +69,11 @@ def get_acros(word, silly, short): try: for idx, letter in enumerate(word): newWord = random.choice( - filter( + list(filter( lambda w: (idx is 0 or not w.strip().lower().endswith("'s")) and w.lower().startswith(letter.lower()), words, - ) + )) ).strip() print(str(idx) + " -> " + newWord) newDef.append(newWord) @@ -85,7 +86,7 @@ def get_acros(word, silly, short): '{}: "{}" ({}, score: {})'.format( word.upper(), newWord, "Tilde.town Original", "0" ) - ).encode("ascii", "ignore") + ) ) except IndexError: acros.append("Future hazy, try again later: Tilde.town Error") diff --git a/Code/irc/banterbot.py b/Code/irc/banterbot.py index 1f73dbf..956e94d 100755 --- a/Code/irc/banterbot.py +++ b/Code/irc/banterbot.py @@ -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 # Import some necessary libraries. +import argparse import socket import os import sys -from optparse import OptionParser import fileinput import random import re @@ -27,9 +28,9 @@ import acronymFinder import util from whosaid import whoSaid -parser = OptionParser() +parser = argparse.ArgumentParser() -parser.add_option( +parser.add_argument( "-s", "--server", dest="server", @@ -37,15 +38,16 @@ parser.add_option( help="the server to connect to", metavar="SERVER", ) -parser.add_option( +parser.add_argument( "-c", - "--channel", - dest="channel", - default="#bot_test", - help="the channel to join", - metavar="CHANNEL", + "--channels", + dest="channels", + nargs="+", + default=["#bot_test"], + help="the channels to join", + metavar="CHANNELS", ) -parser.add_option( +parser.add_argument( "-n", "--nick", dest="nick", @@ -54,13 +56,14 @@ parser.add_option( metavar="NICK", ) -(options, args) = parser.parse_args() +args = parser.parse_args() p = inflect.engine() def joinchan(chan): ircsock.send("JOIN " + chan + "\r\n") + ircsock.send("JOIN #bots\r\n") def hello(): @@ -122,9 +125,9 @@ def score_banter(channel, user, messageText): def get_new_banter(channel, user): 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 - words = filter(lambda word: re.search(r"ant", word), words) + words = list(filter(lambda word: re.search(r"ant", word), words)) random.shuffle(words) word = words[0].strip("\n") start = word.find("ant") @@ -136,7 +139,7 @@ def get_new_banter(channel, user): else: # replace the letter with 'b' word = word[: start - 1] + "b" + word[start:] 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) word = words[0].strip("\n") end = word.find("ban") + 3 @@ -225,8 +228,6 @@ def get_xkcd(channel, text): joined_links = ", ".join(links) for line in [joined_links[i : i + 400] for i in range(0, len(joined_links), 400)]: util.sendmsg(ircsock, channel, line) - # res = xkcdApropos.xkcd(text[6:]) - # ircsock.send("PRIVMSG " + channel + " :" + res + "\n") def get_wphilosophy(channel, text): @@ -251,7 +252,7 @@ def figlet(channel, text): else: lines = subprocess.Popen( ["figlet", "-w140"] + text.split(" "), shell=False, stdout=subprocess.PIPE - ).stdout.read() + ).stdout.read().decode("utf-8") for line in lines.split("\n"): util.sendmsg(ircsock, channel, line) time.sleep(0.4) # to avoid channel throttle due to spamming @@ -265,7 +266,7 @@ def toilet(channel, text): ["toilet", "-w140", "--irc"] + text.split(" "), shell=False, stdout=subprocess.PIPE, - ).stdout.read() + ).stdout.read().decode("utf-8") for line in lines.split("\n"): util.sendmsg(ircsock, channel, line) time.sleep(0.4) # to avoid channel throttle due to spamming @@ -277,7 +278,7 @@ def get_acronym(channel, text): else: defs = acronymFinder.get_acros(text, True, True) 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: util.sendmsg(ircsock, channel, defs[-1]) @@ -337,7 +338,7 @@ def rollcall(channel): def listen(botnick): while 1: - ircmsg = ircsock.recv(2048).decode() + ircmsg = ircsock.recv(2048).decode('utf-8') ircmsg = ircmsg.strip("\n\r") if ircmsg[:4] == "PING": @@ -416,5 +417,5 @@ def listen(botnick): ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -util.connect(ircsock, options) -listen(options.nick) +util.connect(ircsock, args) +listen(args.nick) diff --git a/Code/irc/defineWord.py b/Code/irc/defineWord.py index e290ac0..e7d977f 100644 --- a/Code/irc/defineWord.py +++ b/Code/irc/defineWord.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import urllib from bs4 import BeautifulSoup import random @@ -6,11 +7,11 @@ import random def define(word): defs = [] 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") if head: for p in head.find_all("p"): - defs.append(p.text.encode("ascii", "ignore")) + defs.append(p.text) return defs @@ -22,11 +23,11 @@ def defWord(word, short=True): url = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/{}?key={}".format( word, key ) - soup = BeautifulSoup(urllib.urlopen(url).read(), "html5lib") + soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html5lib") entry = soup.find("entry") if entry: for d in entry.find_all("dt"): - defs.append(d.text.encode("ascii", "ignore")) + defs.append(d.text) if short: return " ".join(defs) else: diff --git a/Code/irc/duckduckgo.py b/Code/irc/duckduckgo.py index b00dda4..767254e 100755 --- a/Code/irc/duckduckgo.py +++ b/Code/irc/duckduckgo.py @@ -47,7 +47,7 @@ def query( "d": meanings, } params.update(kwargs) - encparams = urllib.urlencode(params) + encparams = urllib.parse.urlencode(params) url = "http://api.duckduckgo.com/?" + encparams request = requests.get(url, headers={"User-Agent": useragent}) diff --git a/Code/irc/inflect.pyc b/Code/irc/inflect.pyc index 9feea7f4a1f433ae23f61d765e212e61fef24609..62e9932612e16480f0016ce5c5898a4565196542 100644 GIT binary patch delta 2810 zcmb_edyG_98K3Vv_nv#toileHyYtxDnT6ShJ7pUzZ7C24+I4remLk?iL$K1il7^NL z!T@boOd$~{6^rd8y^x|s8Y$Y;ss|inE2)aF1{xb|F*U)W(HNUzYYA%qp#ILx?y|c+ zqKWh6yuQad-}}z_FSxJlcYX0zB6#NXi>ton?_0=MusO8wnK^vFG^{BrBff>XY!ZaYqVwQv5o zeKqrlZ*KTpp7<8OzINyP>tEY(oImNCwL3%NHNLrb7uI#Y*?qqzuC-Xs?tYoa?6%Xq z_&}C;J8t^COZbJT>Z98G1?a8!l@;7exNz7la#)$iP2 zB-iZNe?50Dn&gfbpr(T%z@MQkKYs2}E`P|4U(^S4=+a0-jP zqMyxG2Q~91RbP6j7_DMb=JrEL4tH2?X}J>xDnuVIaT2 zHYX0hOng|G14nYq$CNqx^_|>zVy3p8uuoEj(=_T>jWC3{^{G7bE6Qwnx{LUNGLL+7 zuET#<^`9IaAz>27R#8s@Ce>0_3$9Ytw~>O;>?KCo;_NWHzq5q;7Ffns;^8gUP6om4 z5=zLHAKJkhnm;sFCcT;!8yho2KmCd;msz>3_18|$zZ$6kEz2T_CuUQMq*!!$PjPoH zmz@quQwL~@JW6x@gQrUEdA4GC9)LG<$R3|&iTc>7HxapYFFft&Epfc?2|O92zWNoX zD_3^F06}re;C9DpYeo}0n*nZ$QtW%(q=m*SDK;BUKT3QmZW1qT;03?4SM@fpN;24; ztQB%{xT3Q)GqM_HlqhtXj?RKPWxjW2MV6(m>(`fmM7(F3QP=*HQE{pWfiz5z12vl~ z5;TBQTXy~nYoB<1*AP_K;PIUT`BV4M(`V~8&2z}l*pnS83~)Br@v~bn_nd#8^&JUV zY2y{s8METejc&&_i@D8WP@fvMS-V50pX$H4xRRt<^w;HrUrLzWZyywVF<}NS`J&v0 zRIkmoLO~Xx@nJ#&k+tQGI$Tcl7B38=_c1-2U20ivR>WHAX;V}-+6BT~x!%$+K+_QQ zDBBGEs7+xzWMhd#AE*3{mamn7wyr#yjSiFM#uI2xXmDZlq@=&_?P23FkA{fXhK=9* zbb)wd*!Xn-y^=fZ1!z!sNYWrjZ^!8*?+K%yY5G3z4I8@>be8$yuyIF<-c5WgjJ}+q z#nI_B{hXf-8#oB!ABEB5ZFCKJjWcbegZT6I(xdj$VsyStTOC0IqOrbp(40O5~iWV4I1BToet`T}u)?4`E0k%2~=$Nb>;WXMwYn$Y2a_LOB?XI_VdI ztjOrqA(|7tF+`3p{Vqq!F4v+;CFym!7&1oF!Qv-{QUwV8TbAO;OsZtef@nT|X^5)!wP0Bj z!I!-#;Zf<}%z()(ktkH@T!k53OLV{$SBjpQDFRoHr`=^sGSP#>q}oL2O!^$c8mH*F zLCR;@Lu+b5fN$e`3I#|9N2nkx_$xHO8J=dE$S5~LX%QEqNoK6L;o9gIgVbv$?F6EN ztb!k}k%(l*ZI+X;26l4=uAg|wBXB09luj1djL34<710j{spGv?hv}e1r`rp*nP8J; TCMZO8m~w$aarTRD>Q4Owj^xRa delta 2582 zcmbtVYm8OZ6~1fjefGWQoPA%zy_Y+WJItLy8AsF*t;I}#v}llF1|K77wEWOOTayxv zGUAhFXlj`jeC8w^ULk-=RH8yR^paSKe;OYF{XrmTQ)1g6jSn=)7@8U%-#Yi=Ol!0; z-j#j#+H0@9_P1X9yuI1`@L?~b&SZl#le?Dg%WRs@&yd?S|HT15rrgadmZW)uj-LP3 zHhxIEk(K|}yj{D6cl?_9pmu**wS@SPcBQ*c62GS1;`(I}A+@c3o)6Be=N{tm#_)#Bqkf9Q3%U53jd3N$n0tHU?bJ0XAWB%Lw51wZgr|)Hgs4E)E#K5dtW30a za|fl}*3Ca*zQ{x;w^oUsIJ=c=3k(hiayYC4x2EpqJ!wdcD{ZfF`36z3(^NX)m|L{N za_txYdwTX1O5^U_HIw;nEb=2ou(6X3ooEQHhM3!xvVU3{<1*kJit>ka}>H)-#eUfs;h*05jKea9=hkyb`I(2J??>^R5>Y|)ZB3{N38A*}78|4r7y6lPb%6vQ% zU3Ti4B{Y|2{FmF;Pjh=N-0f(&oy`Bw?PI4V7Q+t<%IGS_IX;m9c7`RWmIo-)CMy~6 z8uJvFNIXc~jt^hwTt6y$tRjwE1KHiDS9!GsB1?LeBpA6Q7&)zgbtXr2_9pblva{DH z-V(Sy|JkAV#lS83Jfk{K$icZ{ERcrIAd6XKR^cIvR}r1zPlNbYrazY{grXE$s#&;F zyy?b#h49YOvX?XwPzPwBw3K&J+KJY3O+Tfw6|Lr5XQ0)CH>F68H}M=1SHk$Hp^v#I zY`l`DtBCu76viK0dWlEE#=b0_#0wcV9xu=( z#H+&i)ixT8KP%E}d|%kWLJ_YG<0CWZQVJSy&j#UynA|TW+u~|BtM)mxH#!TcY4lt`hqK=3Z2%fiUQXM*(Y0V3n|?@L;hg)y8oV9SNd;BW(@4py z-hA1!@mmXM<+!3i%}YAmBApe=(L9iJd~2OHY|&db4H$qnz=5ip6gA1{ZqKN0ueDO$ z29jiVN;*yVYddBGb$@$X_bjfU$> zJOohH^bl~hKyD3R(pl%a*M=BcjYN{duZ_x{LR#zkTr^T-(CFnMY|A${?d9<=)MgYL zWtD>0X>AS6H079mNHCC)ntURqPVlA6rVSv(g&|rHcMVb3b*352)?Kn`z{_amNhC@T zK&Dd40A~l':".format(botnick), ) @@ -132,7 +134,7 @@ def handle_bot_msg(channel, msg, botnick): # Handle how to quit the game def quit_game(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 @@ -141,12 +143,12 @@ def handle_story_selection(channel, msg, botnick): global state try: imsg = int(msg) - if imsg < 0 or imsg > len(stories[channel]): - sendmsg(channel, "Selection out of bounds. Try again!") + if imsg < 0 or imsg > len(list(stories[channel])): + util.sendmsg(ircsock, channel, "Selection out of bounds. Try again!") return time.sleep(1 * THROTTLE_FACTOR) - sendmsg( - channel, "Give me a second to load up {}".format(stories[channel][imsg][0]) + util.sendmsg( + ircsock, channel, "Give me a second to load up {}".format(stories[channel][imsg][0]) ) 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 story_start(channel, botnick) except ValueError: - sendmsg(channel, "Invalid selection. Try again!") + util.sendmsg(ircsock, channel, "Invalid selection. Try again!") state[channel] = State.story_selection @@ -165,7 +167,8 @@ def story_start(channel, botnick): global nextword state[channel] = State.thinking - sendmsg( + util.sendmsg( + ircsock, channel, "Alright! Let's get started! Say '{}: ' to give me words.".format( botnick @@ -173,7 +176,7 @@ def story_start(channel, botnick): ) nextword[channel] = madlib.find_next_word(story[channel], True) 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 @@ -196,7 +199,8 @@ def handle_story_step(channel, msg): return # else count = madlib.count_words(story[channel]) - sendmsg( + util.sendmsg( + ircsock, channel, "Thanks! Now give me {} ({} words left)".format(nextword[channel][1], count), ) @@ -208,15 +212,15 @@ def finish_story(channel): global state global story - sendmsg(channel, "Ok, here's the story...") - sendmsg(channel, "=" * MAX_LINE) + util.sendmsg(ircsock, channel, "Ok, here's the story...") + util.sendmsg(ircsock, channel, "=" * MAX_LINE) for line in story[channel].splitlines(): for part in madlib.yield_lines(line, MAX_LINE): time.sleep(0.6 * THROTTLE_FACTOR) - sendmsg(channel, part) - padlen = (MAX_LINE - 9) / 2 + util.sendmsg(ircsock, channel, part) + padlen = int((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] = "" state[channel] = State.idle @@ -235,14 +239,16 @@ def rollcall(channel, botnick): state[channel] = State.idle if state[channel] == State.idle: - sendmsg( + util.sendmsg( + ircsock, channel, "Do you like MadLibs? Start a collaborative story by saying '{}: startgame'".format( botnick ), ) else: - sendmsg( + util.sendmsg( + ircsock, channel, "A game is already in progress. Say '{}: ' to provide me with the next word or '{}: !quit' to stop the current game".format( botnick, botnick @@ -255,11 +261,11 @@ def listen(botnick): "^{}\:?\s*(.*)$".format(botnick) ) # re to strip the bot's name from a message while 1: - ircmsg = ircsock.recv(2048) + ircmsg = ircsock.recv(2048).decode("utf-8") ircmsg = ircmsg.strip("\n\r") if ircmsg[:4] == "PING": - ping(ircmsg.split(" ")[1]) + util.ping(ircsock, ircmsg) formatted = util.format_message(ircmsg) if "" == formatted: @@ -287,5 +293,5 @@ def listen(botnick): ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -util.connect(ircsock, options) -listen(options.nick) +util.connect(ircsock, args) +listen(args.nick) diff --git a/Code/irc/quote_bot.py b/Code/irc/quote_bot.py index 600b1e2..8f1cc20 100755 --- a/Code/irc/quote_bot.py +++ b/Code/irc/quote_bot.py @@ -77,7 +77,7 @@ def say_chatty(channel): def listen(): while 1: - ircmsg = ircsock.recv(2048).decode() + ircmsg = ircsock.recv(2048).decode("utf-8") ircmsg = ircmsg.strip("\r\n") formatted = util.format_message(ircmsg) diff --git a/Code/irc/rhymesWith.py b/Code/irc/rhymesWith.py index 6d19ea1..ce6d10e 100644 --- a/Code/irc/rhymesWith.py +++ b/Code/irc/rhymesWith.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import urllib # from lxml.html import fromstring @@ -8,7 +9,7 @@ import random def getRhymes(word): words = [] 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"): 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" % 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"): w = t.text.rstrip() if w not in [u"", u"\xa0"] and "?" not in t: - words.append(w.encode("ascii", "ignore")) + words.append(w) random.shuffle(words) return words[0:5] diff --git a/Code/irc/run_banter.sh b/Code/irc/run_banter.sh index 7599650..2e3b02d 100755 --- a/Code/irc/run_banter.sh +++ b/Code/irc/run_banter.sh @@ -1,9 +1,9 @@ #!/bin/bash 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" - #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 echo "Banterbot has already been started" fi diff --git a/Code/irc/run_madlib.sh b/Code/irc/run_madlib.sh index eae894b..0fd18db 100755 --- a/Code/irc/run_madlib.sh +++ b/Code/irc/run_madlib.sh @@ -1,7 +1,7 @@ #!/bin/bash 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" else echo "madlibbot has already been started" diff --git a/Code/irc/run_tilde.sh b/Code/irc/run_tilde.sh index 8584a7f..da66d45 100755 --- a/Code/irc/run_tilde.sh +++ b/Code/irc/run_tilde.sh @@ -1,5 +1,8 @@ #!/bin/bash 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 -#nohup ./tildebot.py -s 127.0.0.1 -n tildebot -c \#bot_test >> tildelog 2>> tildelog & diff --git a/Code/irc/run_topic.sh b/Code/irc/run_topic.sh index 94213ab..3a619c5 100755 --- a/Code/irc/run_topic.sh +++ b/Code/irc/run_topic.sh @@ -1,6 +1,6 @@ #!/bin/bash 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 -#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 diff --git a/Code/irc/tildebot.py b/Code/irc/tildebot.py index ca76109..2f9e9a6 100755 --- a/Code/irc/tildebot.py +++ b/Code/irc/tildebot.py @@ -6,7 +6,7 @@ import socket import os import sys import time -from optparse import OptionParser +import argparse import fileinput import random @@ -14,9 +14,9 @@ import inflect import puzzle import util -parser = OptionParser() +parser = argparse.ArgumentParser() -parser.add_option( +parser.add_argument( "-s", "--server", dest="server", @@ -24,15 +24,16 @@ parser.add_option( help="the server to connect to", metavar="SERVER", ) -parser.add_option( +parser.add_argument( "-c", - "--channel", - dest="channel", - default="#bot_test", - help="the channel to join", - metavar="CHANNEL", + "--channels", + dest="channels", + nargs="+", + default=["#bot_test"], + help="the channels to join", + metavar="CHANNELS", ) -parser.add_option( +parser.add_argument( "-n", "--nick", dest="nick", @@ -41,7 +42,7 @@ parser.add_option( metavar="NICK", ) -(options, args) = parser.parse_args() +args = parser.parse_args() p = inflect.engine() challenges = {} @@ -325,7 +326,7 @@ def rollcall(channel): def listen(): while 1: - ircmsg = ircsock.recv(2048).decode() + ircmsg = ircsock.recv(2048).decode("utf-8") for msg in ircmsg.split("\n"): msg = msg.strip("\n\r") @@ -334,7 +335,7 @@ def listen(): continue formatted = util.format_message(msg) - print(formatted) + # print(formatted) if "" == formatted: continue @@ -360,5 +361,5 @@ def listen(): ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -util.connect(ircsock, options) +util.connect(ircsock, args) listen() diff --git a/Code/irc/tildescores.txt b/Code/irc/tildescores.txt index d10b485..b31ad93 100644 --- a/Code/irc/tildescores.txt +++ b/Code/irc/tildescores.txt @@ -1,4 +1,4 @@ -krowbar&^%2430&^%1540473099 +krowbar&^%2507&^%1541083807 karlen&^%498&^%1527613440 endorphant&^%682&^%1444775660 jumblesale&^%24&^%1426171214 @@ -55,11 +55,11 @@ tybaltcat&^%7&^%1481076625 minerbot&^%146&^%1520382015 mio&^%347&^%1529720473 archangel&^%479&^%1538689239 -tehfraga&^%656&^%1540457107 +tehfraga&^%669&^%1540933836 sushi&^%10&^%1493253212 troido&^%302&^%1538991819 gamebot&^%199&^%1538991833 -nilaky&^%1406&^%1540432090 +nilaky&^%1445&^%1541047850 bucket&^%103&^%1507931139 lolbot&^%1&^%1502568407 m455&^%12&^%1512076715 @@ -73,7 +73,7 @@ emfor&^%3&^%1509671353 k2l8m11n2&^%11&^%1510932395 sacredpix&^%3&^%1522082931 deltawitc&^%3267&^%1538609961 -login&^%2395&^%1540411798 +login&^%2446&^%1541083668 kelpiebot&^%3&^%1513101957 unreal&^%2&^%1534387108 tildethie&^%5612&^%1538710812 @@ -93,7 +93,7 @@ saturn597&^%3&^%1521429369 cwmccabe&^%2&^%1521598124 lucidiot&^%28&^%1526201925 tracer&^%1&^%1521744878 -jan6&^%1087&^%1540323640 +jan6&^%1088&^%1540831048 jan&^%10&^%1522319160 etathetae&^%3&^%1522937843 eeeeeta&^%52&^%1540361066 @@ -106,15 +106,15 @@ Halian&^%32&^%1528360263 lunasspec&^%4&^%1524164784 bowlercap&^%3&^%1524165068 littlebig&^%46&^%1535927253 -severak&^%16&^%1533802439 +severak&^%17&^%1540822455 ralph&^%4&^%1526980620 benjaminw&^%526&^%1538599664 -von&^%404&^%1540199114 +von&^%407&^%1540980176 ensis&^%1750&^%1539356542 simon&^%26&^%1527937489 -benharri&^%1962&^%1540473154 +benharri&^%2055&^%1541052332 cpb&^%3&^%1528930564 -calmbit&^%150&^%1537918704 +calmbit&^%156&^%1540942599 wisebot&^%5613&^%1539612163 paannd_a&^%2&^%1529617165 nincollin&^%6&^%1531186900 @@ -123,20 +123,22 @@ pounce&^%19&^%1532133325 von_&^%5&^%1532502104 livix&^%7&^%1533603142 ben&^%3&^%1533767627 -npa&^%78&^%1536235183 +npa&^%84&^%1541066354 ezo&^%6&^%1533883842 -aliasless&^%31&^%1539879035 -kirch&^%41&^%1535571833 +aliasless&^%36&^%1541001821 +kirch&^%51&^%1541006239 root&^%2&^%1535558514 byte&^%5&^%1536416308 qbe&^%7&^%1537850181 informati&^%3&^%1536733938 h00fi&^%1&^%1537050053 -fantoro&^%4&^%1540021663 -tildethief&^%783&^%1540475833 -benjaminwil&^%7&^%1539378917 -deltawitch&^%11&^%1539184112 -archangelic&^%1&^%1540407712 +fantoro&^%7&^%1540854244 +tildethief&^%1051&^%1541084586 +benjaminwil&^%9&^%1541018886 +deltawitch&^%12&^%1540915500 +archangelic&^%2&^%1540574433 diodelass&^%3&^%1539382302 minerobber&^%4&^%1540467667 brendantcc&^%3&^%1539908223 +dozens&^%16&^%1540784558 +bowlercaptain&^%3&^%1540926135 diff --git a/Code/irc/topicbot.py b/Code/irc/topicbot.py index b7cdf98..5c253e5 100755 --- a/Code/irc/topicbot.py +++ b/Code/irc/topicbot.py @@ -1,21 +1,21 @@ -#!/usr/bin/python +#!/usr/bin/python3 # http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python # Import some necessary libraries. import socket import os import sys -from optparse import OptionParser import fileinput import random import time +import argparse import inflect import util -parser = OptionParser() +parser = argparse.ArgumentParser() -parser.add_option( +parser.add_argument( "-s", "--server", dest="server", @@ -23,15 +23,16 @@ parser.add_option( help="the server to connect to", metavar="SERVER", ) -parser.add_option( +parser.add_argument( "-c", - "--channel", - dest="channel", - default="#bot_test", - help="the channel to join", - metavar="CHANNEL", + "--channels", + dest="channels", + nargs="+", + default=["#bot_test"], + help="the channels to join", + metavar="CHANNELS", ) -parser.add_option( +parser.add_argument( "-n", "--nick", dest="nick", @@ -40,7 +41,7 @@ parser.add_option( metavar="NICK", ) -(options, args) = parser.parse_args() +args = parser.parse_args() p = inflect.engine() @@ -162,7 +163,7 @@ def topic_history(channel, user, count): def listen(): while 1: - ircmsg = ircsock.recv(2048).decode() + ircmsg = ircsock.recv(2048).decode("utf-8") ircmsg = ircmsg.strip("\n\r") if ircmsg[:4] == "PING": @@ -177,7 +178,7 @@ def listen(): 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) if ircmsg.find(":!topic") != -1: @@ -207,5 +208,5 @@ def listen(): ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -util.connect(ircsock, options) +util.connect(ircsock, args) listen() diff --git a/Code/irc/topicscores.txt b/Code/irc/topicscores.txt index b89d459..c31e1c0 100644 --- a/Code/irc/topicscores.txt +++ b/Code/irc/topicscores.txt @@ -1,2 +1,2 @@ vilmibm&^%0&^%4 -krowbar&^%0&^%1vantablack&^%1&^%0 +krowbar&^%2&^%1vantablack diff --git a/Code/irc/tumblr.py b/Code/irc/tumblr.py index f835878..c4411d2 100644 --- a/Code/irc/tumblr.py +++ b/Code/irc/tumblr.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import urllib from bs4 import BeautifulSoup import random @@ -6,7 +7,7 @@ import re def tumble(url): # 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("/")[ 1 ] # this could totally fail several ways @@ -17,7 +18,7 @@ def tumble(url): # Parse a page 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")) quote = article.find("blockquote").text.replace("\n", "") diff --git a/Code/irc/util.py b/Code/irc/util.py index e3da9ed..d5e9b89 100644 --- a/Code/irc/util.py +++ b/Code/irc/util.py @@ -41,7 +41,11 @@ def connect(ircsock, options): mode = "MODE +B {}\r\n".format(options.nick).encode() print(mode) ircsock.send(mode) - joinchan(ircsock, options.channel) + if 'channels' in options: + for channel in options.channels: + joinchan(ircsock, channel) + else: + joinchan(ircsock, options.channel) # integer number to english word conversion diff --git a/Code/irc/wangbot.py b/Code/irc/wangbot.py index 5e08bee..faa216b 100755 --- a/Code/irc/wangbot.py +++ b/Code/irc/wangbot.py @@ -281,7 +281,7 @@ def rollcall(channel): def listen(): while 1: - ircmsg = ircsock.recv(2048).decode() + ircmsg = ircsock.recv(2048).decode("utf-8") ircmsg = ircmsg.strip("\n\r") if ircmsg[:4] == "PING": diff --git a/Code/irc/xkcdApropos.py b/Code/irc/xkcdApropos.py index 166785b..fd73042 100644 --- a/Code/irc/xkcdApropos.py +++ b/Code/irc/xkcdApropos.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import duckduckgo import urllib from bs4 import BeautifulSoup @@ -10,7 +11,7 @@ def xkcd(query): title = BeautifulSoup(urllib.urlopen(res).read(), "html.parser").title.text except: 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 @@ -19,7 +20,8 @@ def xkcd(query): # soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser') # items = soup.find_all("a", class_="result__a") # 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 # def pretty_link(item): # url = item.find(class_="result__url").text.strip() diff --git a/public_html/chatcloud/index.html b/public_html/chatcloud/index.html index 7d9b3bc..51d4c49 100644 --- a/public_html/chatcloud/index.html +++ b/public_html/chatcloud/index.html @@ -13,6 +13,7 @@