New backup of tildescores and added jackpot to tildebot

This commit is contained in:
Russell 2015-02-02 19:47:47 +00:00
parent 9ecd97dff1
commit 886b86d2cc
3 changed files with 51 additions and 23 deletions

View File

@ -2,4 +2,3 @@
nohup ./tildebot.py -s 127.0.0.1 -n tildebot -c \#tildetown >> tildelog 2>> tildelog &
#nohup ./tildebot.py -s 127.0.0.1 -n tildebot -c \#bot_test >> tildelog 2>> tildelog &
#./topic_bot.py -s 127.0.0.1 -n topic_bot -c \#bot_test

View File

@ -27,6 +27,10 @@ parser.add_option("-n", "--nick", dest="nick", default='tildebot',
(options, args) = parser.parse_args()
p = inflect.engine()
SCORE_FILE = "tildescores.txt"
JACKPOT_FILE = "tildejackpot.txt"
JACKPOT_MIN = 3
DEBUG = False
def ping():
ircsock.send("PONG :pingis\n")
@ -47,16 +51,34 @@ def too_recent(time1, time2):
return False
def get_prize(user):
if(random.randint(1,10) > 2):
if(random.randint(1,10) > 2): #80% of the time it's a normal prize
prizes = [1] * 8 + [2] * 4 + [3] * 2 + [5] * 1
prize = random.choice(prizes)
return [prize, user + " is " + ("super " if prize > 4 else "really " if prize > 2 else "") + "cool and gets " + p.number_to_words(prize) + " tildes!"]
else:
return [0, user + " is a meanie and gets no tildes!"]
else: #20% of the time its a jackpot situation
with open(JACKPOT_FILE, "r+") as jackpotfile:
jackpot = int(jackpotfile.readline().strip("\n"))
jackpotfile.seek(0)
jackpotfile.truncate()
if(random.randint(1,10) > 1): #90% of the time it's a non-prize
new_jackpot = jackpot+1
jackpotfile.write(str(new_jackpot)) #increase the jackpot by 1
return [0, user + " is a meanie and gets no tildes! (Jackpot is now " + str(new_jackpot) + " tildes)"]
else: #hit jackpot!
jackpotfile.write(str(JACKPOT_MIN))
return [jackpot, user + " hit the jackpot and got " + p.number_to_words(jackpot) + " tildes!"]
def show_jackpot(channel):
with open(JACKPOT_FILE, "r") as jackpotfile:
jackpot = int(jackpotfile.readlines().strip("\n"))
ircsock.send("PRiVMSG " + channel + " :The jackpot is currently " + p.number_to_words(jackpot) + " tildes!\n")
def give_tilde(channel, user, time):
if(channel != "#bots" and not DEBUG):
ircsock.send("PRIVMSG " + channel + " :" + user + " is a meanie and gets no tildes. **Tildebot now only gives out tildes in the #bots channel.**\n")
return
found = False
with open("tildescores.txt", "r+") as scorefile:
with open(SCORE_FILE, "r+") as scorefile:
scores = scorefile.readlines()
scorefile.seek(0)
scorefile.truncate()
@ -64,7 +86,7 @@ def give_tilde(channel, user, time):
person = score.strip("\n").split("&^%")
if(person[0] == user):
found = True
if(too_recent(time, person[2])):
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)
@ -77,7 +99,7 @@ def give_tilde(channel, user, time):
scorefile.write(user + "&^%" + str(prize[0]+1) + "&^%" + time + "\n")
def show_tildescore(channel, user):
with open("tildescores.txt", "r") as scorefile:
with open(SCORE_FILE, "r") as scorefile:
for idx,score in enumerate(scorefile):
person = score.strip("\n").split("&^%")
if(person[0] == user):
@ -95,6 +117,7 @@ def connect(server, channel, botnick):
ircsock.send("NICK "+ botnick +"\n")
joinchan(channel)
joinchan("#bots")
def get_user_from_message(msg):
try:
@ -132,6 +155,9 @@ def listen():
elif ircmsg.find(":!tilde") != -1:
give_tilde(channel, user, time)
if ircmsg.find(":!jackpot") != -1:
show_jackpot(channel)
if ircmsg.find(":!rollcall") != -1:
rollcall(channel)

View File

@ -1,19 +1,22 @@
krowbar&^%33&^%1422565422
karlen&^%15&^%1422291058
endorphant&^%62&^%1422561985
jumblesale&^%18&^%1422027769
marcus&^%12&^%1421960027
papa&^%41&^%1422542104
epicmorphism&^%3&^%1421937744
audy&^%27&^%1422542589
kc&^%16&^%1422326056
krowbar&^%43&^%1422902127
karlen&^%38&^%1422291058
endorphant&^%101&^%1422905595
jumblesale&^%20&^%1422027769
marcus&^%15&^%1421960027
papa&^%45&^%1422542104
epicmorphism&^%5&^%1421937744
audy&^%42&^%1422899452
kc&^%18&^%1422326056
vilmibm&^%3&^%1421887627
cmr&^%6&^%1422388018
imt&^%95&^%1422565426
cndorphant&^%125&^%1422395920
rain&^%15&^%1422310975
sl2c&^%28&^%1422524176
cmr&^%16&^%1422388018
imt&^%121&^%1422905648
cndorphant&^%165&^%1422903662
rain&^%17&^%1422310975
sl2c&^%42&^%1422524176
leni&^%2&^%1421978450
selfsame&^%1&^%1422230012
bear&^%46&^%1422561755
coaxial&^%4&^%1422325983
bear&^%68&^%1422903670
coaxial&^%8&^%1422325983
joe&^%8&^%1422325983
hardmath123&^%4&^%1422325983
leni&^%3&^%1422325983