Added some more debugging stuffs to banterbot. Fixed some utils

This commit is contained in:
Russell 2018-11-20 16:41:16 -05:00
parent f2dbad05af
commit d7842734ac
7 changed files with 87 additions and 55 deletions

View File

@ -55,6 +55,14 @@ parser.add_argument(
help="the nick to use",
metavar="NICK",
)
parser.add_argument(
"-o",
"--owner",
dest="owner",
default="krowbar",
help="the owner of this bot",
metavar="OWNER",
)
args = parser.parse_args()
@ -225,7 +233,8 @@ def get_xkcd(channel, text):
def get_wphilosophy(channel, text):
steps = wikiphilosophy.get_philosophy_lower(text[17:])
util.sendmsg(ircsock, channel, "Ok, give me a minute while I look up '{}'".format(text))
steps = wikiphilosophy.get_philosophy_lower(text)
if not steps:
util.sendmsg(
ircsock, channel, "Couldn't find a wikipedia entry for {}".format(text)
@ -302,7 +311,7 @@ def get_whosaid(channel, text):
def get_notice(user, channel):
ircsock.send("CNOTICE " + user + " " + channel + " :Notice me senpai!\r\n")
util.notice(ircsock, user, channel, "Notice me senpai!")
def get_water(user, channel, msg, botnick):
@ -316,12 +325,9 @@ def mug_off(channel):
def rollcall(channel):
text = """
U wot m8? I score all the top drawer #banter and #bantz on this channel!
Find new top-shelf banter with !newbanter, !rhymes, and !define.
Look up things with !acronym and !whosaid.
Make your chatter #legend with !rainbow, !toilet, and !figlet.
Find interesting things with !xkcd and !wiki-philosophy.
Get jokes with !welch and !evil
U wot m8? I score all the top drawer #banter and #bantz on this channel! / Find new top-shelf banter with !newbanter, !rhymes, and !define.
Look up things with !acronym and !whosaid / Make your chatter #legend with !rainbow, !toilet, and !figlet.
Find interesting things with !xkcd and !wiki-philosophy / Get jokes with !welch !evil !kjp and !help
"""
for line in textwrap.dedent(text).split("\n"):
if line == "":
@ -337,6 +343,7 @@ def listen(botnick):
if ircmsg[:4] == "PING":
util.ping(ircsock, ircmsg)
print("** " + ircmsg)
continue
formatted = util.format_message(ircmsg)
@ -344,66 +351,77 @@ def listen(botnick):
if "" == formatted:
continue
# print formatted
print(formatted)
_time, user, _command, channel, messageText = formatted.split("\t")
if ircmsg.find("#banter") != -1 or ircmsg.find("#bantz") != -1:
if messageText.find("#banter") != -1 or messageText.find("#bantz") != -1:
score_banter(channel, user, messageText)
if ircmsg.find(":!newbanter") != -1:
if messageText.startswith("!newbanter"):
get_new_banter(channel, user)
if ircmsg.find(":!rhymes") != -1:
if messageText.startswith("!rhymes"):
get_rhymes(channel, user, messageText)
if ircmsg.find(":!define") != -1:
if messageText.startswith("!define"):
define_word(channel, user, messageText)
if ircmsg.find(":!rainbow") != -1:
if messageText.startswith("!rainbow"):
make_rainbow(channel, user, messageText)
if ircmsg.find(":!welch") != -1:
if messageText.startswith("!welch"):
get_welch(channel)
if ircmsg.find(":!evil") != -1:
if messageText.startswith("!evil"):
get_evil(channel)
if ircmsg.find(":!kjp") != -1:
if messageText.startswith("!kjp"):
get_tumble("http://kingjamesprogramming.tumblr.com", channel)
if ircmsg.find(":!help") != -1:
if messageText.startswith("!help"):
get_tumble("http://thedoomthatcametopuppet.tumblr.com", channel)
if ircmsg.find(":!xkcd") != -1:
if messageText.startswith("!xkcd"):
get_xkcd(channel, messageText)
if ircmsg.find(":!wiki-philosophy") != -1:
get_wphilosophy(channel, messageText)
if ircmsg.find(":!figlet") != -1:
if messageText.startswith("!wiki-philosophy"):
get_wphilosophy(channel, messageText[17:])
if messageText.startswith("!figlet"):
figlet(channel, messageText[8:])
if ircmsg.find(":!toilet") != -1:
if messageText.startswith("!toilet"):
toilet(channel, messageText[8:])
if ircmsg.find(":!acronym") != -1:
if messageText.startswith("!acronym"):
get_acronym(channel, messageText[9:])
if ircmsg.find(":!whosaid") != -1:
if messageText.startswith("!whosaid"):
get_whosaid(channel, messageText[9:])
if ircmsg.find(":!notice") != -1:
if messageText.startswith("!notice"):
get_notice(user, channel)
if ircmsg.find(":!water") != -1:
if messageText.startswith("!water"):
get_water(user, channel, messageText[7:], botnick)
if ircmsg.find(":!rollcall") != -1:
if messageText.startswith("!rollcall"):
rollcall(channel)
if ircmsg.find(":" + botnick + ":") != -1:
if messageText.startswith(botnick + ":"):
mug_off(channel)
if messageText.startswith("!join") and user == args.owner:
util.joinchan(ircsock, messageText[6:])
if messageText.startswith("!part") and user == args.owner:
util.part(ircsock, messageText[6:])
if messageText.startswith("!quit") and user == args.owner:
util.part(ircsock, "Later chumps!")
return
sys.stdout.flush()
time.sleep(1)
@ -412,6 +430,6 @@ def listen(botnick):
# ROOT: i commented this out until it stops pegging the CPU.
#ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#util.connect(ircsock, args)
#listen(args.nick)
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
util.connect(ircsock, args)
listen(args.nick)

View File

@ -3,7 +3,7 @@
if [[ ! `pidof -sx banterbot.py` ]]; then
#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:6667 -n banterbot -c \#bots >> banterlog 2>> banterlog &
nohup ./banterbot.py -s 127.0.0.1:6667 -n banterbot -c \#tildetown \#bots >> banterlog 2>> banterlog &
else
echo "Banterbot has already been started"
fi

View File

@ -1,4 +1,4 @@
krowbar&^%2590&^%1542633864
krowbar&^%2596&^%1542728099
karlen&^%498&^%1527613440
endorphant&^%801&^%1444775660
jumblesale&^%25&^%1426171214
@ -43,7 +43,7 @@ cosnok&^%807&^%1508878859
escobar&^%1&^%1475431401
amicabot&^%30&^%1481225205
caff&^%1030&^%1540040705
kadin&^%18&^%1541514839
kadin&^%19&^%1542733284
desvox&^%36&^%1542379512
mankins&^%3&^%1480211581
cinch&^%2&^%1480454755
@ -57,7 +57,7 @@ tehfraga&^%671&^%1542490496
sushi&^%10&^%1493253212
troido&^%302&^%1538991819
gamebot&^%203&^%1542505151
nilaky&^%1501&^%1542491307
nilaky&^%1511&^%1542738605
bucket&^%103&^%1507931139
lolbot&^%1&^%1502568407
m455&^%12&^%1512076715
@ -70,8 +70,8 @@ pinhook&^%8&^%1509744722
emfor&^%3&^%1509671353
k2l8m11n2&^%11&^%1510932395
sacredpix&^%3&^%1522082931
deltawitch&^%3304&^%1542620562
login&^%2633&^%1542634018
deltawitch&^%3309&^%1542655912
login&^%2643&^%1542737740
kelpiebot&^%3&^%1513101957
unreal&^%2&^%1534387108
tildethief&^%7421&^%1542467787
@ -90,7 +90,7 @@ saturn597&^%3&^%1521429369
cwmccabe&^%2&^%1521598124
lucidiot&^%28&^%1526201925
tracer&^%1&^%1521744878
jan6&^%1116&^%1542487863
jan6&^%1116&^%1542729468
jan&^%10&^%1522319160
etathetae&^%3&^%1522937843
eeeeeta&^%52&^%1540361066
@ -104,10 +104,10 @@ lunasspec&^%4&^%1524164784
littlebigly&^%49&^%1535927253
severak&^%17&^%1540822455
ralph&^%4&^%1526980620
von&^%425&^%1542623529
von&^%426&^%1542728162
ensis&^%1750&^%1539356542
simon&^%26&^%1527937489
benharri&^%2277&^%1542609742
benharri&^%2295&^%1542743369
cpb&^%3&^%1528930564
calmbit&^%160&^%1542220635
wisebot&^%5652&^%1542183214
@ -118,23 +118,23 @@ pounce&^%19&^%1532133325
von_&^%5&^%1532502104
livix&^%7&^%1533603142
ben&^%3&^%1533767627
npa&^%139&^%1542620546
npa&^%146&^%1542708198
ezo&^%6&^%1533883842
aliasless&^%36&^%1541001821
kirch&^%213&^%1542401397
kirch&^%217&^%1542659656
root&^%2&^%1535558514
byte&^%5&^%1536416308
qbe&^%7&^%1537850181
informati&^%3&^%1536733938
h00fi&^%1&^%1537050053
fantoro&^%26&^%1542538478
benjaminwil&^%550&^%1542409435
fantoro&^%31&^%1542657642
benjaminwil&^%553&^%1542737924
diodelass&^%3&^%1539382302
brendantcc&^%3&^%1539908223
dozens&^%21&^%1542222479
bowlercaptain&^%6&^%1540926135
nicole&^%6&^%1541276844
midnightpupil&^%12&^%1542216854
ahriman&^%79&^%1542617214
tunas&^%37&^%1542583679
ahriman&^%97&^%1542748742
tunas&^%79&^%1542748854
khuxkm&^%2&^%1542566334

View File

@ -41,7 +41,7 @@ def tumble(url):
)
# just the date and notes
return quote.encode("ascii", "ignore")
return quote
except: # sometimes we fail. let's retry a few times
if tries == 0:
return ""

View File

@ -3,15 +3,28 @@ import time
import random
import re
MAX_LINE = 400
def ping(ircsock, msg):
ircsock.send("PONG {}\n".format(msg.split(" ")[1]).encode())
def sendmsg(ircsock, chan, msg):
print("sending {} to {}".format(msg, chan))
ircsock.send("PRIVMSG {} :{}\r\n".format(chan, msg).encode())
print("sending {} to {}".format(msg, chan)[0:MAX_LINE])
ircsock.send("PRIVMSG {} :{}\r\n".format(chan, msg).encode()[0:MAX_LINE])
def notice(ircsock, user, chan, msg):
print("sending notice {} to {} in {}".format(msg, user, chan)[0:MAX_LINE])
ircsock.send("CNOTICE {} {} :{}\r\n".format(user, chan, msg).encode()[0:MAX_LINE])
def part(ircsock, chan, msg="Bye!"):
print("leaving channel {}".format(chan))
ircsock.send("PART {} {}\r\n".format(chan, msg).encode())
def quit(ircsock, msg="Quitting!"):
print("!! quitting !!")
ircsock.send("QUIT {}".format(msg).encode())
def joinchan(ircsock, chan):
print("joining {}".format(chan))

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
import fileinput
import time
import calendar
@ -7,7 +7,7 @@ import operator
MAX_NODES = 5
logfile = "/home/jumblesale/Code/irc/log"
logfile = "/home/archangelic/irc/log"
timeCutoff = calendar.timegm(time.gmtime()) - (3 * 7 * 24 * 60 * 60) # 3 weeks
nameFix = {
@ -31,7 +31,7 @@ def whoSaid(word):
try:
time, user, message = line.split("\t", 3)
time = int(time)
if nameFix.has_key(user):
if user in nameFix:
user = nameFix[user]
else:
user = user.lower()

View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
import urllib
from bs4 import BeautifulSoup
import random
@ -9,7 +10,7 @@ def get_philosophy(word, max_steps=20):
url = "https://en.wikipedia.org/wiki/%s" % word
while steps < max_steps:
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser")
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
title = soup.find("h1", id="firstHeading")
content = soup.find("div", id="mw-content-text")
if not content:
@ -49,7 +50,7 @@ def get_philosophy_lower(word, max_steps=20):
url = "https://en.wikipedia.org/wiki/%s" % word
while steps < max_steps:
soup = BeautifulSoup(urllib.urlopen(url).read(), "html.parser")
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
title = soup.find("h1", id="firstHeading")
content = soup.find("div", id="mw-content-text")
if not content: