shifting things around to merge in remote
This commit is contained in:
parent
8015111f76
commit
8b75865c4d
|
@ -103,5 +103,6 @@ ENV/
|
|||
jeopardy.db
|
||||
tildechat.py
|
||||
maddshark.py
|
||||
poligoon.py
|
||||
localhost.py
|
||||
|
||||
*.swp
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import emoji
|
||||
from mastodon import Mastodon
|
||||
import pinhook.plugin as p
|
||||
|
||||
with open(os.path.join(path, "config.json")) as f:
|
||||
config = json.load(f)
|
||||
|
||||
Masto = Mastodon(
|
||||
client_id=config["mastodon"]["client_id"],
|
||||
client_secret=config["mastodon"]["client_secret"],
|
||||
access_token=config["mastodon"]["access_token"],
|
||||
api_base_url=config["mastodon"]["base_url"],
|
||||
)
|
||||
|
||||
|
||||
@p.register('!toot')
|
||||
def tooter(msg):
|
||||
try:
|
||||
res = Masto.toot(msg.args)
|
||||
return p.message("Tooted: {}".format(res["url"]))
|
||||
except e:
|
||||
msg.logger.error(e);
|
||||
return p.message("Toot failed!")
|
|
@ -26,5 +26,5 @@ def gen_string(msg):
|
|||
if msg.arg:
|
||||
if (msg.arg in list_grammars):
|
||||
return p.message(generate(msg.arg + ".json"))
|
||||
return p.message("Available grammars: " + ", ".join(os.listdir(drammar_dir)))
|
||||
return p.message("Available grammars: " + ", ".join(os.listdir(grammar_dir)))
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def addlink(msg):
|
|||
@p.register('!addlink')
|
||||
@p.ops('!addlink', 'add a link')
|
||||
def addlink(msg):
|
||||
return p.message(ssh('~/addlink.sh ' + msg.arg))
|
||||
return p.message(ssh('~/add_link.sh ' + msg.arg))
|
||||
|
||||
@p.register('!twtxt')
|
||||
@p.ops('!twtxt', 'post to twtxt')
|
||||
|
|
|
@ -5,7 +5,7 @@ import json
|
|||
import operator
|
||||
import shelve
|
||||
import fuzzyset
|
||||
from random import choice
|
||||
from random import choice, randint
|
||||
|
||||
"""
|
||||
A plugin for playing Jeopardy!
|
||||
|
@ -64,28 +64,34 @@ def compare(guess, answer):
|
|||
for item in metric:
|
||||
tally += item[0]
|
||||
average = tally / len(metric)
|
||||
print("answer: " + answer + " || guess: " + guess + " || match: " + str(average))
|
||||
if average > 0.45:
|
||||
return True
|
||||
|
||||
|
||||
def markinvalid(msg):
|
||||
key = (msg.nick, msg.channel, msg.bot.servers[0].host)
|
||||
if key in jeopardy_tmp:
|
||||
req = http.Request("http://jservice.io/api/invalid/", { "id": jeopardy_tmp[key]["id"] })
|
||||
api = http.urlopen(req)
|
||||
data = json.loads(api.read())
|
||||
del jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
||||
if (data.invalid_count == None):
|
||||
return "Something went wrong, question not updated."
|
||||
try:
|
||||
key = (msg.nick, msg.channel, msg.bot.servers[0].host)
|
||||
if key in jeopardy_tmp:
|
||||
req = http.Request("http://jservice.io/api/invalid/", { "id": str(jeopardy_tmp[key]["id"]) })
|
||||
api = http.urlopen(req)
|
||||
data = json.loads(api.read())
|
||||
del jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
||||
if (data.invalid_count == None):
|
||||
return "Something went wrong, question not updated."
|
||||
else:
|
||||
return "Question marked as invalid."
|
||||
else:
|
||||
return "Question marked as invalid."
|
||||
return "I'm sorry, I don't recall you asking a question."
|
||||
except e:
|
||||
msg.logger.error(e)
|
||||
return "Something went wrong, question not updated"
|
||||
|
||||
|
||||
def getquestion(msg, value):
|
||||
if value:
|
||||
api = http.urlopen("http://jservice.io/api/clues/?count=10&value=" + value.strip() + "&offset=" + str(randint(1,10000))).read().strip()
|
||||
else:
|
||||
return "I'm sorry, I don't recall you asking a question."
|
||||
|
||||
|
||||
def getquestion(msg):
|
||||
api = http.urlopen("http://jservice.io/api/random/?count=10").read().strip()
|
||||
api = http.urlopen("http://jservice.io/api/random/?count=10").read().strip()
|
||||
data = json.loads(api)
|
||||
try:
|
||||
if data:
|
||||
|
@ -107,10 +113,10 @@ def jeopardyreply(msg):
|
|||
answer = jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["answer"]
|
||||
guess = re.search(formquestion_rex, msg.text)
|
||||
if guess:
|
||||
print("regexed guess")
|
||||
msg.logger.info("regexed guess")
|
||||
guess = guess.group("answer")
|
||||
else:
|
||||
print("non-regexed guess")
|
||||
msg.logger.info("non-regexed guess")
|
||||
guess = msg.text
|
||||
if answer and guess and (answer.lower() == guess.lower() or compare(guess, answer)):
|
||||
points = jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["points"]
|
||||
|
@ -125,6 +131,7 @@ def jeopardyreply(msg):
|
|||
@p.register('!j', 'Ask a Jeopardy Question')
|
||||
@p.register('!jeopardy', 'Ask a Jeopardy Question')
|
||||
def jeopardy(msg):
|
||||
value = None
|
||||
if msg.arg == "help" or msg.arg == "?":
|
||||
return p.message("!j [score(s)|invalid|help] - !j without arguments (or with incorrect arguments) will return a question - If the question is missing a video or image use `!j invalid` to mark it as impossible to answer - you can see your points total with `!j score`")
|
||||
elif msg.arg == "score" or msg.arg == "points":
|
||||
|
@ -134,13 +141,16 @@ def jeopardy(msg):
|
|||
elif msg.arg == "scores" or msg.arg == "leaderboard" or msg.arg == "leaders":
|
||||
return p.message(leaderboard(msg.channel))
|
||||
else:
|
||||
args = msg.arg.split(' ')
|
||||
if len(args) and args[0] == "compare":
|
||||
return p.message(str(compare(args[1], args[2])))
|
||||
args = msg.arg.strip().split(' ')
|
||||
if len(args):
|
||||
if args[0] == "compare":
|
||||
return p.message(str(compare(args[1], args[2])))
|
||||
elif msg.arg.strip().isdigit():
|
||||
value = msg.arg
|
||||
|
||||
output = getquestion(msg)
|
||||
output = getquestion(msg, value)
|
||||
if output:
|
||||
return p.message("{}: The Category is '{}'. {}: {}".format(msg.nick, output["cat"], choice(alex["ask"]), output["q"]))
|
||||
return p.message("{}: The Category is '{}', for ${}. {}: {}".format(msg.nick, output["cat"], output["points"], choice(alex["ask"]), output["q"]))
|
||||
else:
|
||||
return p.message("{}: An error occurred attempting to find a question.".format(msg.nick))
|
||||
|
||||
|
|
Loading…
Reference in New Issue