Added some stuff, deleted some stuff, modified some stuff

This commit is contained in:
Russell 2016-03-10 11:54:42 -05:00
parent 8454515e67
commit d76dd9c674
16 changed files with 199 additions and 30 deletions

View File

@ -1 +0,0 @@
This is a test of the GitLab hosting thing a ma thing

35
Code/irc/acronymFinder.py Normal file
View File

@ -0,0 +1,35 @@
import urllib
from bs4 import BeautifulSoup
import random
(userId,token) = open("/home/krowbar/.secret/s4token").readline().rstrip().split(',')
def get_acros(word):
acros = []
url = "http://www.stands4.com/services/v2/abbr.php?uid=%s&tokenid=%s&term=%s" % (userId, token, word)
soup = BeautifulSoup(urllib.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 = []
for r in results:
rdef = r.find('definition').text
match = next((x for x in defs if x['definition'] == rdef), None)
if match is not None:
#if we find a match, add the category to the existing categories and increase the score
match['categories'].append(((r.find('parentcategoryname').text + '\\') if r.find('parentcategoryname') else '') + r.find('categoryname').text)
match['score'] = str(float(match['score']) + float(r.find('score').text))
else: #add a new item
defs.append({\
'term': r.find('term').text,\
'definition': r.find('definition').text,\
'categories': [((r.find('parentcategoryname').text + '\\') if r.find('parentcategoryname') else '') + r.find('categoryname').text],\
'score': r.find('score').text\
});
for d in sorted(defs, key=lambda x:float(x['score']), reverse=True):
#print d;
acros.append(("%s: \"%s\" (%s, score: %s)" % \
(d['term'], d['definition'], ', '.join(d['categories']), d['score'])\
).encode('ascii', 'ignore'))
return acros

View File

@ -9,6 +9,7 @@ from optparse import OptionParser
import fileinput
import random
import re
import subprocess
import formatter
import get_users
@ -23,6 +24,8 @@ import welch
import evil
import tumblr
import xkcdApropos
import wikiphilosophy
import acronymFinder
parser = OptionParser()
@ -126,6 +129,7 @@ def get_rhymes(channel, user, text):
def define_word(channel, user, text):
word = ""
defs = []
if(len(text.split(' ')) > 1):
word = text.split(' ')[1]
defs = defWord(word)
@ -143,7 +147,7 @@ def get_welch(channel):
ircsock.send("PRIVMSG " + channel + " :" + welch.get_thing()[0:400] + "\n")
def get_evil(channel):
evilThing = evil.get_thing();
evilThing = evil.get_thing()
for line in [evilThing[i:i+400] for i in range(0, len(evilThing), 400)]:
ircsock.send("PRIVMSG " + channel + " :" + line + "\n")
@ -160,6 +164,33 @@ def get_xkcd(channel, text):
#res = xkcdApropos.xkcd(text[6:])
#ircsock.send("PRIVMSG " + channel + " :" + res + "\n")
def get_wphilosophy(channel, text):
steps = wikiphilosophy.get_philosophy_lower(text[17:])
if not steps:
ircsock.send("PRIVMSG " + channel + " :Couldn't find a wikipedia entry for " + text + "\n")
else:
joined_steps = ' > '.join(steps)
if steps[-1] == 'Philosophy':
joined_steps += "!!!"
for line in [joined_steps[i:i+400] for i in range(0, len(joined_steps), 400)]:
ircsock.send("PRIVMSG " + channel + " :" + line + "\n")
def figlet(channel, text):
if not text:
ircsock.send("PRIVMSG " + channel + " :No text given. :(\n")
else:
lines = subprocess.Popen(["figlet", "-w80"] + text.split(' '), shell=False, stdout=subprocess.PIPE).stdout.read()
for line in lines.split('\n'):
ircsock.send("PRIVMSG " + channel + " :" + line + "\n")
def get_acronym(channel, text):
if not text:
ircsock.send("PRIVMSG " + channel + " :No text given :(\n")
else:
defs = acronymFinder.get_acros(text)
for d in defs[0:5]: #only the first five. they are already sorted by 'score'
ircsock.send("PRIVMSG " + channel + " :" + d + "\n")
def rollcall(channel):
ircsock.send("PRIVMSG "+ channel +" :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. Make your chatter #legend with !rainbow and get jokes with !welch and !evil\n")
@ -231,6 +262,14 @@ def listen():
if ircmsg.find("!xkcd") != -1:
get_xkcd(channel, messageText)
if ircmsg.find("!wiki-philosophy") != -1:
get_wphilosophy(channel, messageText);
if ircmsg.find("!figlet") != -1:
figlet(channel, messageText[8:])
if ircmsg.find("!acronym") != -1:
get_acronym(channel, messageText[9:])
if ircmsg.find(":!rollcall") != -1:
rollcall(channel)

View File

@ -20,6 +20,6 @@ def rhymeZone(word):
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)
words.append(w.encode('ascii', 'ignore'))
random.shuffle(words)
return words[0:5]

View File

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

View File

@ -53,10 +53,10 @@ def too_recent(time1, time2):
else:
return False
def get_prize(user, isHuman):
def get_prize(user, isHuman, bonus=0):
if(random.randint(1,10) > 6 - 4 * isHuman): #80% of the time it's a normal prize (40% for not humans)
prizes = [1] * 8 + [2] * 4 + [3] * 2 + [5] * isHuman #no 5pt prize for non-humans
prize = random.choice(prizes)
prize = random.choice(prizes) + bonus
return [prize, user + ": " + (random.choice(['Yes','Yep','Correct','You got it']) if isHuman else random.choice(['No', 'Nope', 'Sorry', 'Wrong']))\
+ "! You are " + ("super " if prize > 4 else "really " if prize > 2 else "") + "cool and get " + p.number_to_words(prize) + " tildes!"]
else: #20% of the time its a jackpot situation
@ -77,7 +77,7 @@ def show_jackpot(channel):
jackpot = int(jackpotfile.readline().strip("\n"))
ircsock.send("PRiVMSG " + channel + " :The jackpot is currently " + p.number_to_words(jackpot) + " tildes!\n")
def give_tilde(channel, user, time, human):
def give_tilde(channel, user, time, human, bonus=0):
found = False
with open(SCORE_FILE, "r+") as scorefile:
scores = scorefile.readlines()
@ -90,12 +90,12 @@ def give_tilde(channel, user, time, human):
if(too_recent(time, person[2]) and not DEBUG):
ircsock.send("PRIVMSG " + channel + " :You have asked for a tilde too recently. Try again later.\n")
else:
prize = get_prize(user, human)
prize = get_prize(user, human, bonus)
score = person[0] + "&^%" + str(int(person[1]) + prize[0]) + "&^%" + time + "\n"
ircsock.send("PRIVMSG " + channel + " :" + prize[1] + "\n")
scorefile.write(score)
if(not found):
prize = get_prize(user, True)
prize = get_prize(user, True, bonus)
ircsock.send("PRIVMSG " + channel + " :Welcome to the tilde game! Here's " + p.number_to_words(prize[0]+1) + " free tilde(s) to start you off.\n")
scorefile.write(user + "&^%" + str(prize[0]+1) + "&^%" + time + "\n")
@ -122,10 +122,11 @@ def challenge_response(channel, user, time, msg):
global challenges
print(msg);
if(challenges.has_key(user)):
bonus = 1 if str(challenges[user]).find(',') != -1 else 0 #give a bonus for prime factoring
if(msg == str(challenges[user]) or msg == p.number_to_words(challenges[user])):
give_tilde(channel, user, time, True);
give_tilde(channel, user, time, True, bonus);
else:
give_tilde(channel, user, time, False);
give_tilde(channel, user, time, False, 0);
del challenges[user]; #delete the user from challenges either way

View File

@ -1,20 +1,20 @@
krowbar&^%399&^%1454593921
krowbar&^%568&^%1457628524
karlen&^%272&^%1449500011
endorphant&^%682&^%1444775660
jumblesale&^%24&^%1426171214
marcus&^%877&^%1454436882
marcus&^%1017&^%1457620552
papa&^%179&^%1438878499
epicmorphism&^%5&^%1421937744
audy&^%78&^%1442345315
kc&^%18&^%1422326056
vilmibm&^%9&^%1445468087
cmr&^%1131&^%1454335852
cmr&^%1138&^%1457560235
imt&^%519&^%1424087616
cndorphant&^%788&^%1424094192
rain&^%17&^%1422310975
sl2c&^%91&^%1424847521
selfsame&^%1&^%1422230012
bear&^%223&^%1452518640
bear&^%234&^%1457620876
coaxial&^%8&^%1422325983
joe&^%8&^%1422325983
hardmath123&^%4&^%1422325983
@ -28,13 +28,14 @@ reppard&^%11&^%1437512059
jesse&^%6&^%1437569027
khoi&^%3&^%1438044039
sanqui&^%4&^%1438184911
endorphan&^%64&^%1452614950
cndorphbo&^%2&^%1447862524
endorphan&^%65&^%1456348638
cndorphbo&^%4&^%1455813639
santi&^%3&^%1447873216
insom&^%1&^%1450346059
tahnok&^%3&^%1450457276
nilsding&^%12&^%1454100197
vypr&^%3&^%1452470872
synergian&^%21&^%1454583808
dheeraj&^%2&^%1454438936
dheeraj&^%5&^%1456489270
demobot&^%6&^%1454439605
premysl&^%19&^%1456882805

View File

@ -20,3 +20,5 @@
1451487092&^%krowbar&^%Bots rule! Users drool!
1453394948&^%krowbar&^%We'll leave it to the future to resolve the present
1453924207&^%krowbar&^%The best things happen when you're parsing
1455303761&^%krowbar&^%Writing bots for fun and profit!
1456153721&^%krowbar&^%BOTS OF TILDE TOWN, RISE FROM YOUR GRAVES!

View File

@ -131,3 +131,5 @@
1451971379&^%vilmibm&^%let's talk about html & feels | welcome new users!
1452017977&^%vilmibm&^%let's talk about html & feels! | add yrself to the map of townies! http://tilde.town/~bear/where.html
1453427743&^%vilmibm&^%WHAT MOVIE SHOULD WE WATCH IN ASCII ON MOVIE NIGHT? | add yrself to the map http://tilde.town/~bear/where.html
1455911894&^%vilmibm&^%RESTART IMMINENT | OUT YOUR CRUSHES | WATCH THE WORLD BURN
1456278388&^%vilmibm&^%how about the feels tho?

View File

@ -1,6 +1,7 @@
krowbar&^%9&^%19
vilmibm&^%0&^%20
krowbar&^%10&^%21
vilmibm&^%0&^%22
hardmath123&^%0&^%6
joe&^%1&^%1jumblesale
audiodude&^%1&^%0
cmr&^%0&^%3
insom&^%1&^%0

View File

@ -0,0 +1,50 @@
import urllib
from bs4 import BeautifulSoup
import random
def get_philosophy(word, max_steps=20):
step_words = [word]
steps = 0
url = 'https://en.wikipedia.org/wiki/%s' % word
while steps < max_steps:
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
title = soup.find('h1', id='firstHeading')
content = soup.find('div', id='mw-content-text')
if not content:
break
item = [item for item in content.find_all('a') if not item.get('class') and not item.get('target') and item.get('title') and not 'Wikipedia:' in item.get('title') and not 'Category:' in item.get('title') and not 'Help:' in item.get('title') and not 'Portal:' in item.get('title') and not 'Special:' in item.get('title') and not 'Talk:' in item.get('title') and not 'Template:' in item.get('title') and not 'File:' in item.get('title') and 'Edit section:' not in item.get('title') and 'Commons:' not in item.get('title') and not item.get('title') in step_words][0]
step_words.append(item.get('title'))
#print item.get('title') + "\n"
url = 'https://en.wikipedia.org%s' % item.get('href')
steps += 1
return step_words
def containsAny(str, set):
return 1 in [c in str for c in set]
def get_philosophy_lower(word, max_steps=20):
step_words = [word]
steps = 0
url = 'https://en.wikipedia.org/wiki/%s' % word
while steps < max_steps:
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
title = soup.find('h1', id='firstHeading')
content = soup.find('div', id='mw-content-text')
if not content:
break
links = [item for item in content.find_all('a') if not item.get('class') and item.text and item.text[0].islower() and not containsAny(item.text, ':()') and item.get('title') and not containsAny(item.get('title'), ':()') and not item.get('title') in step_words]
if not links:
step_words.append("(dead end)")
break
item = links[0] #grab the first good link item
#print "Checking %s %s" % (item.get('title'), item.text)
step_words.append(item.get('title'))
if item.get('title') == 'Philosophy':
break
#print item.get('title') + "\n"
url = 'https://en.wikipedia.org%s' % item.get('href')
steps += 1
return step_words

View File

@ -11,7 +11,7 @@ userData = {} #hash keyed by "user" that contains an array of timestamps
#we only care about recent chats, let's say for the past couple weeks
oneWeek = 7 * 24 * 60 * 60
fiveMinutes = 5 * 60
timeCutoff = calendar.timegm(time.gmtime()) - (2 * oneWeek)
timeCutoff = calendar.timegm(time.gmtime()) - (5 * oneWeek)
with open(logfile, "r") as log:
for line in log:

View File

@ -8,12 +8,15 @@ import shutil
logfile = "/home/jumblesale/Code/irc/log"
outfile = "/home/krowbar/logs/chatcloud.json"
#outfile = "/home/krowbar/logs/chatcloud_2016_01.json"
bannedUsersFile = "/home/krowbar/Code/python/bannedUsers"
bannedWordsFile = "/home/krowbar/Code/python/bannedWords"
wordData = {} # keyed by "word" that contains a count
#we only care about recent chats, let's say for the past sixteen hours
timeTo = calendar.timegm(time.gmtime())
#timeTo = calendar.timegm(time.strptime("1 Feb 16", "%d %b %y"))
timeCutoff = timeTo - (16 * 60 * 60)
#timeCutoff = calendar.timegm(time.strptime("1 Jan 16", "%d %b %y"))
print "Generating word cloud based off words from " + str(timeCutoff) + " to " + str(timeTo)
minOccurance = 3 #we'll have to reduce the minOccurances if we reduce the timeCutoff
minLength = 3 #number of letters long

View File

@ -12,16 +12,42 @@ charset="utf-8"></script>-->
google.load("visualization", "1", {packages:["timeline"]});
data = [];
threshold = 5;
threeDays = 3 * 86400;
oneWeek = 7 * 86400; <!-- seconds in a week -->
jQuery.getJSON("/~krowbar/data/userData.json", function(json) {
_.forEach(json, function(times, user) {
console.log("~" + user + ":", times.length, "item(s)");
_.forEach(times, function(time) {
d = new Date(0);
d.setUTCSeconds(Number(time));
<!--data.push([user, d.toISOString().slice(11,16), d, d]);-->
data.push([user, d, d]);
})
if(times.length > threshold) {
console.log("~" + user + ":", times.length, "item(s)");
_.forEach(times, function(time) {
d = new Date(0);
d.setUTCSeconds((Number(time) + threeDays) % oneWeek - threeDays);
<!--data.push([user, d.toISOString().slice(11,16), d, d]);-->
data.push([user, d, d]);
});
}
});
<!-- compress the data -->
data.sort(); <!-- to get the multi-week dates adjusted-->
timeThreshold = 30 * 60 * 1000; <!-- five minutes in milliseconds -->
removeCount = 0;
for(var i = 0; i < data.length-1;) {
removed = false;
if(data[i][0] == data[i+1][0]) { <!--name check-->
if(data[i][2].getTime() + timeThreshold > data[i+1][1].getTime() &&
data[i][2].getTime() < data[i+1][2].getTime() ) { <!--time check-->
<!-- console.log('Combining items', data[i][2].getTime(), data[i+1][1].getTime()); -->
data[i][2] = data[i+1][2];
data.splice(i+1,1); <!--remove item i+1-->
removed = true;
removeCount++;
}
}
if(!removed) {
i++;
}
}
console.log('Removed', removeCount, 'items');
//google.setOnLoadCallback(drawChart);
$(drawChart);
});

View File

@ -4,6 +4,10 @@
<div>
<select id="series">
<option value="">Today</option>
<option value="_2016_01">Jan 2016</option>
<option value="_2015_12">Dec 2015</option>
<option value="_2015_11">Nov 2015</option>
<option value="_2015_10">Oct 2015</option>
<option value="_2015_09">Sep 2015</option>
<option value="_2015_08">Aug 2015</option>
<option value="_2015_07">July 2015</option>

View File

@ -7,7 +7,7 @@
var self = this;
var adjectives = Array('Ancient','Bold','Breaking','Brightest','Brilliant','Crescent','Dark|Darkness','Darkest|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Giant|Giant','Glorious|Glory','Joyful|Joy','July','Last','Liberty|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Righteous','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Silent','Soaring','Standing|Stand','Star|Star','Stunning','Super','Thunderous|Thunder','Twisted','Urgent','Utopian','Valiant');
var adjectives = Array('Ancient','Bold','Breaking','Brightest','Brilliant','Crescent','Dark|Darkness','Darkest|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Giant|Giant','Glorious|Glory','Joyful|Joy','July','Last','Liberty|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Righteous','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Silent','Sleeping','Soaring','Standing|Stand','Star|Star','Stunning','Super','Thunderous|Thunder','Twisted','Urgent','Utopian','Valiant');
var nouns = Array('Action','Alert','Bane','Beauty','Claw','Darkness','Dawn','Day','Defense','Desert','Envy','Fall','Fist','Flight','Fury','Guard','Glory','Hammer','Hand','Honor','Hope','Hunt','Hurricane','Joy','Liberty','Light','Lightning','Magic','Morning','October','Power','Rain','Response','Repose','Roar','Scream','Skull','Sky','Skies','Shield','Shout','Stand','Star','Storm','Streak','Strike','Sun','Thunder','Victory','Whisper','Wind','Wrath');
var colors = Array('Black','Blue','Brown','Golden','Gray','Green','Indego','Orange','Purple','Rainbow','Red','Scarlet','Silver','Violet','White','Yellow');
var actors = Array('Cobra','Condor','Dragon','Eagle','Giant','Guardian','Hawk','Hydra','Jackal','King','Knight','Lady','Lion','Scorpion','Spartan','Stranger','Titan','Victor','Viking','Warrior');
@ -24,7 +24,8 @@ var mission_grammars = Array(
{chance:5, grammar: "{noun1} of {color} {noun2}"},
{chance:10, grammar: "{adj1} {noun1} and {adj2} {noun2}"},
{chance:3, grammar: "Attack of the {actor}s"},
{chance:3, grammar: "Return of the {actor}s"}
{chance:3, grammar: "Return of the {actor}s"},
{chance:1, grammar: "The {actor} Awakens"}
);
this.getNoun = function(badNouns) {
return _.chain(nouns)