how 2 git. Honestly I should probably stop having these awful merges fucking everywhere if I actually want others to contribute
This commit is contained in:
Jacob Henry 2016-11-29 23:01:57 +00:00
commit c55023b026
3 changed files with 178 additions and 1 deletions

View File

@ -5,7 +5,7 @@ from SlackUtil import *
from WaitonUtil import handleWaitonMsg #For waitons
from ScrollUtil import handleScrollMsg #For scrolls
from TrueScrollUtil import handleTrueScrollMsg #For true scrolls
from kong import handleKongMsg
import re
#Read api token from file
@ -47,6 +47,7 @@ waiton_pattern = re.compile("^waiton")
scroll_pattern = re.compile("^scroll")
true_scroll_pattern = re.compile("^truescroll")
housejob_pattern = re.compile("^(house)?job")
kong_pattern = re.compile("")
def main():
#Init slack
@ -95,6 +96,10 @@ def main():
elif housejob_pattern.match(text):
print("Received housejob from " + user['user']['name'])
reply(slack, msg, "I cannot do that (yet)", username="sadbot")
elif kong_pattern.match(text):
print("Received kong from " + user['user']['name'])
handleKongMsg(slack, msg)
elif killswitch == msg['text'].lower():
reply(slack, msg, "as you wish...", username="rip bot")

103
kong.py Normal file
View File

@ -0,0 +1,103 @@
import threading
import re
from SlackUtil import reply
from time import sleep
DEFAULT_SONG = "dk_rap_classic"
#Patterns
patterns = {}
patterns['start'] = re.compile("^#STARTSONG (.*?)")
patterns['time'] = re.compile("^#TIMEPERLINE (\\d*)")
patterns['rest'] = re.compile("^#REST")
patterns['end'] = re.compile("^#ENDSONG")
#SongContents
lyric_lines = []
f = open("lyrics.txt")
for line in f:
lyric_lines += [line]
f.close()
class SongThread(threading.Thread):
def __init__(this, replycallback, song_name):
this.slack = slack
this.song_name = song_name
this.song_lines = song_lines
this.delay = 1000
this.daemon = True
def run(this):
playing = False
for line in lyric_lines:
if line == "":
continue
#Navigate to song start
if not playing:
if m = patterns['start'].match(line):
if m.group(1) == this.song_name:
playing = True
continue
#Play loop
else:
#Config
if m = patterns['time'].match(line):
this.delay = int(m.group(1))
#Rest line
elif m = patterns['rest'].match(line):
sleep(this.delay / 1000)
#End song
elif m = patterns['end'].match(line):
return
#"sing" line
else:
replycallback(line)
sleep(this.delay / 1000)
if not playing:
replycallback("Could not find song")
def getAllTitles():
titles = []
for line in lyric_lines:
if m = patterns['start'].match(line):
titles += [m.group(1)]
return titles
request_pattern = re.compile("kong (.*?)$")
def handleKongMsg(slack, msg):
#Get text
text = msg['text']
match = request_pattern.match(text)
if match:
#Make callback function
reply_callback = lambda response: reply(slack, msg, response, username="jukebot")
if match.group(1) == "list":
response = ""
for title in getAllTitles():
response = response + title
reply_callback(response)
elif match.group(1) != "":
st = SongThread(reply_callback, m.group(1))
st.start()
else:
st = SongThread(reply_callback, DEFAULT_SONG)
st.start()
else:
response = "Invoke as kong <songtitle:list>"

69
lyrics.txt Normal file
View File

@ -0,0 +1,69 @@
#STARTSONG dk_rap_classic
#TIMEPERLINE 750
So they're finally here, performing for you
If you know the words, you can join in too
Put your hands together, if you want to clap
As we take you through this monkey rap
DK
Donkey Kong
He's the leader of the bunch, you know him well
He's finally back to kick some tail
His coconut gun can fire in spurts
If he shoots ya, it's gonna hurt
He's bigger, faster, and stronger too
He's the first member of the DK crew
DK
Donkey Kong
DK
Donkey Kong is here
This Kong's got style, so listen up dudes
She can shrink in size, to suit her mood
She's quick and nimble when she needs to be
She can float through the air and climb up trees
If you choose her, you'll not choose wrong
With a skip and a hop, she's one cool Kong
DK
Donkey Kong
He has no style, he has no grace
This Kong has a funny face
He can handstand when he needs to
And stretch his arms out, just for you
Inflate himself just like a balloon
This crazy Kong just digs this tune
DK
Donkey Kong
DK
Donkey Kong is here
He's back again and about time too
And this time he's in the mood
He can fly real high with his jetpack on
With his pistols out, he's one tough Kong
He'll make you smile when he plays his tune
But Kremlings beware cause he's after you
DK
Donkey Kong
Finally, he's here for you
It's the last member of the DK crew
This Kong's so strong, it isn't funny
Can make a Kremling cry out for mummy
Can pick up a boulder with relative ease
Makes crushing rocks seem such a breeze
He may move slow, he can't jump high
But this Kong's one hell of a guy
C'mon Cranky, take it to the fridge!
Walnuts, peanuts, pineapple smells
Grapes, melons, oranges and coconut shells
#ENDSONG