Update minercoin
This commit is contained in:
parent
6b6a780f76
commit
2691cf6a74
|
@ -1,4 +1,4 @@
|
|||
import plugin
|
||||
import plugin, os
|
||||
|
||||
@plugin.listener("admin")
|
||||
def admin(bot,channel,nick,msg):
|
||||
|
@ -15,6 +15,19 @@ def admin(bot,channel,nick,msg):
|
|||
bot.nick = args[0]
|
||||
elif subcmd=="prefix":
|
||||
bot.prefix = args[0]
|
||||
elif subcmd=="minercoin":
|
||||
subsubcmd = args.pop(0)
|
||||
if subsubcmd=="reset":
|
||||
value = args.pop(0)
|
||||
if value=="all" or value=="times":
|
||||
os.remove("times.json")
|
||||
if value=="all" or value=="challenges":
|
||||
os.remove("challenges.json")
|
||||
if value=="all" or value=="scores":
|
||||
os.remove("minercoin.json")
|
||||
bot.load_module("minercoin","plugins/minercoin.py")
|
||||
elif subsubcmd=="reload":
|
||||
bot.load_module("minercoin","plugins/minercoin.py")
|
||||
|
||||
@plugin.listener("water_joke")
|
||||
def water_joke(bot,channel,nick,msg):
|
||||
|
|
|
@ -7,7 +7,7 @@ How it works:
|
|||
- If the answer is correct, reward the user with MinerCoins.
|
||||
- If not, no reward is issued.
|
||||
- Only let the user try a challenge every hour."""
|
||||
import plugin, time, random
|
||||
import plugin, time, random, traceback, datetime
|
||||
from pluralslib import plural
|
||||
from dictdata import DictData
|
||||
|
||||
|
@ -15,8 +15,12 @@ challenges = DictData("challenges.json")
|
|||
last_used = DictData("times.json")
|
||||
count = DictData("minercoin.json")
|
||||
|
||||
def get(source):
|
||||
username = source.user
|
||||
def username(f):
|
||||
def __username(bot,channel,nick,*args):
|
||||
return f(bot,channel,nick,bot.event.source.user.strip(),*args)
|
||||
return __username
|
||||
|
||||
def get(username):
|
||||
return count.get(username,0), last_used.get(username,0), challenges.get(username)
|
||||
|
||||
def set(source,ncount,nlast_used,nchallenge=None):
|
||||
|
@ -25,20 +29,32 @@ def set(source,ncount,nlast_used,nchallenge=None):
|
|||
last_used[username]=nlast_used
|
||||
challenges[username]=nchallenge
|
||||
|
||||
names = "Alice Bob Carol Danvers Eve Frank Gerald Hope Indiana Jared Kate Larry Monica Nathan Orion Peter Quibley Ryan Stewart Tobias Uriah Violet Warren Xylia Yvonne Zelda".split()
|
||||
|
||||
# OK, this needs explaining.
|
||||
# [int count, lambda verify, lambda answer, string question]
|
||||
# count = how many numbers to generate
|
||||
questions = [
|
||||
[2,lambda x,y: (x>=0 and x<=100),lambda x,y: int(round((x/100.)*y)),"Calculate {}% of {}. (round to the nearest whole number)"]
|
||||
# [2,lambda x,y: (x>=0 and x<=100),lambda x,y: int(round((x/100.)*y)),"Calculate {}% of {}. (round to the nearest whole number)"],
|
||||
[1,lambda x: (x<182),lambda x: names[x%26],"If I introduce you to {}, what is their name?",lambda x: [names[x%26]]],
|
||||
[2,lambda x,y: (x<195 and y<195),lambda x,y: (x%13)*(y%13),"Calculate {} times {}.",lambda x,y: [(i%13) for i in (x,y)]]
|
||||
]
|
||||
|
||||
def safelist(n):
|
||||
try:
|
||||
return list(n)
|
||||
except TypeError:
|
||||
return [n]
|
||||
|
||||
def get_question():
|
||||
q = random.choice(questions)
|
||||
nums = [random.randint(0,200) for x in range(q[0])]
|
||||
while not q[1](*nums):
|
||||
nums = [random.randint(0,200) for x in range(q[0])]
|
||||
chq = q[3].format(*nums)
|
||||
cha = str(q[2](*nums))
|
||||
if len(q)==5:
|
||||
nums = safelist(q[4](*nums))
|
||||
chq = q[3].format(*nums)
|
||||
return chq, cha
|
||||
|
||||
@plugin.group("minercoin","<ask/count/cooldown>")
|
||||
|
@ -54,34 +70,53 @@ def minercoin(bot,channel,nick,*args):
|
|||
leadins = ["pro-minercoin question","anti-autoasker question","pro-login question","pro-minerobber challenge"]
|
||||
|
||||
@minercoin.command("ask")
|
||||
def minercoin_ask(bot,channel,nick,*args):
|
||||
cnt, last, challenge = get(bot.event.source)
|
||||
if (int(time.time())-last)<(60*60) and nick!="minerobber": # if it hasn't been an hour since the last one...
|
||||
@username
|
||||
def minercoin_ask(bot,channel,nick,username,*args):
|
||||
cnt, last, challenge = get(username)
|
||||
if (int(time.time())-last)<(60*60): # if it hasn't been an hour since the last one...
|
||||
bot.say(channel,"{} is a doodoo head and needs to wait longer between attempts! (1 hour between attempts)".format(nick))
|
||||
return
|
||||
question, challenge = get_question()
|
||||
bot.say(channel,"{}: {}: {}".format(nick,random.choice(leadins),question))
|
||||
set(bot.event.source,cnt,time.time(),challenge)
|
||||
try:
|
||||
question, challenge = get_question()
|
||||
bot.say(channel,"{}: {}: {}".format(nick,random.choice(leadins),question))
|
||||
set(bot.event.source,cnt,int(time.time()),challenge)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
@plugin.listener("minercoin_answer")
|
||||
def minercoin_listen(bot,channel,nick,message):
|
||||
cnt, last, challenge = get(bot.event.source)
|
||||
@username
|
||||
def minercoin_listen(bot,channel,nick,username,message):
|
||||
cnt, last, challenge = get(username)
|
||||
if challenge is None: return
|
||||
elif message==challenge:
|
||||
bot.say(channel,"{}: You are a winner and get 1 MinerCoin!".format(nick))
|
||||
cnt+=1
|
||||
payout = random.randint(1,5)
|
||||
bot.say(channel,"{}: You are a winner and get {}!".format(nick,plural(payout,"MinerCoin")))
|
||||
cnt+=payout
|
||||
else:
|
||||
bot.say(channel,"{} is a quitter and gets no MinerCoin!".format(nick))
|
||||
set(bot.event.source,cnt,last,None)
|
||||
|
||||
@minercoin.command("count")
|
||||
def minercoin_count(bot,channel,nick,*args):
|
||||
if bot.event.source.user in count:
|
||||
cnt = get(bot.event.source)[0]
|
||||
bot.say(channel,"{}: You have {}".format(nick,plural(cnt,"MinerCoin")))
|
||||
@username
|
||||
def minercoin_count(bot,channel,nick,username,*args):
|
||||
if username in count:
|
||||
cnt = get(username)[0]
|
||||
bot.say(channel,"{}: You have {}!".format(nick,plural(cnt,"MinerCoin")))
|
||||
else:
|
||||
bot.say(channel,"{}: You don't have any MinerCoin! Get some by asking! (!minercoin ask)".format(nick))
|
||||
|
||||
@minercoin.command("cooldown")
|
||||
def minercoin_cooldown(bot,channel,nick,*args):
|
||||
bot.say(channel,NYI)
|
||||
@username
|
||||
def minercoin_cooldown(bot,channel,nick,username,*args):
|
||||
last = get(username)[1]
|
||||
if last==0: # special case: never used before
|
||||
bot.say(channel,"{}: You can ask for more MinerCoin right away!".format(nick))
|
||||
else:
|
||||
delta = 3600-(int(time.time())-last)
|
||||
delta = int(round(delta))
|
||||
minutes,seconds = divmod(delta,60)
|
||||
timedesc = ""
|
||||
if minutes:
|
||||
timedesc += plural(minutes,"minute")+" and "
|
||||
timedesc += plural(seconds,"second")
|
||||
bot.say(channel,"{}: Please wait {} before asking for more MinerCoin.".format(nick,timedesc))
|
||||
|
|
Loading…
Reference in New Issue