shifting things around to merge in remote
This commit is contained in:
parent
8015111f76
commit
8b75865c4d
|
@ -103,5 +103,6 @@ ENV/
|
||||||
jeopardy.db
|
jeopardy.db
|
||||||
tildechat.py
|
tildechat.py
|
||||||
maddshark.py
|
maddshark.py
|
||||||
|
poligoon.py
|
||||||
localhost.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:
|
||||||
if (msg.arg in list_grammars):
|
if (msg.arg in list_grammars):
|
||||||
return p.message(generate(msg.arg + ".json"))
|
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.register('!addlink')
|
||||||
@p.ops('!addlink', 'add a link')
|
@p.ops('!addlink', 'add a link')
|
||||||
def addlink(msg):
|
def addlink(msg):
|
||||||
return p.message(ssh('~/addlink.sh ' + msg.arg))
|
return p.message(ssh('~/add_link.sh ' + msg.arg))
|
||||||
|
|
||||||
@p.register('!twtxt')
|
@p.register('!twtxt')
|
||||||
@p.ops('!twtxt', 'post to twtxt')
|
@p.ops('!twtxt', 'post to twtxt')
|
||||||
|
|
|
@ -5,7 +5,7 @@ import json
|
||||||
import operator
|
import operator
|
||||||
import shelve
|
import shelve
|
||||||
import fuzzyset
|
import fuzzyset
|
||||||
from random import choice
|
from random import choice, randint
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A plugin for playing Jeopardy!
|
A plugin for playing Jeopardy!
|
||||||
|
@ -64,15 +64,15 @@ def compare(guess, answer):
|
||||||
for item in metric:
|
for item in metric:
|
||||||
tally += item[0]
|
tally += item[0]
|
||||||
average = tally / len(metric)
|
average = tally / len(metric)
|
||||||
print("answer: " + answer + " || guess: " + guess + " || match: " + str(average))
|
|
||||||
if average > 0.45:
|
if average > 0.45:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def markinvalid(msg):
|
def markinvalid(msg):
|
||||||
|
try:
|
||||||
key = (msg.nick, msg.channel, msg.bot.servers[0].host)
|
key = (msg.nick, msg.channel, msg.bot.servers[0].host)
|
||||||
if key in jeopardy_tmp:
|
if key in jeopardy_tmp:
|
||||||
req = http.Request("http://jservice.io/api/invalid/", { "id": jeopardy_tmp[key]["id"] })
|
req = http.Request("http://jservice.io/api/invalid/", { "id": str(jeopardy_tmp[key]["id"]) })
|
||||||
api = http.urlopen(req)
|
api = http.urlopen(req)
|
||||||
data = json.loads(api.read())
|
data = json.loads(api.read())
|
||||||
del jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
del jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
||||||
|
@ -82,9 +82,15 @@ def markinvalid(msg):
|
||||||
return "Question marked as invalid."
|
return "Question marked as invalid."
|
||||||
else:
|
else:
|
||||||
return "I'm sorry, I don't recall you asking a question."
|
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):
|
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:
|
||||||
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)
|
data = json.loads(api)
|
||||||
try:
|
try:
|
||||||
|
@ -107,10 +113,10 @@ def jeopardyreply(msg):
|
||||||
answer = jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["answer"]
|
answer = jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["answer"]
|
||||||
guess = re.search(formquestion_rex, msg.text)
|
guess = re.search(formquestion_rex, msg.text)
|
||||||
if guess:
|
if guess:
|
||||||
print("regexed guess")
|
msg.logger.info("regexed guess")
|
||||||
guess = guess.group("answer")
|
guess = guess.group("answer")
|
||||||
else:
|
else:
|
||||||
print("non-regexed guess")
|
msg.logger.info("non-regexed guess")
|
||||||
guess = msg.text
|
guess = msg.text
|
||||||
if answer and guess and (answer.lower() == guess.lower() or compare(guess, answer)):
|
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"]
|
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('!j', 'Ask a Jeopardy Question')
|
||||||
@p.register('!jeopardy', 'Ask a Jeopardy Question')
|
@p.register('!jeopardy', 'Ask a Jeopardy Question')
|
||||||
def jeopardy(msg):
|
def jeopardy(msg):
|
||||||
|
value = None
|
||||||
if msg.arg == "help" or msg.arg == "?":
|
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`")
|
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":
|
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":
|
elif msg.arg == "scores" or msg.arg == "leaderboard" or msg.arg == "leaders":
|
||||||
return p.message(leaderboard(msg.channel))
|
return p.message(leaderboard(msg.channel))
|
||||||
else:
|
else:
|
||||||
args = msg.arg.split(' ')
|
args = msg.arg.strip().split(' ')
|
||||||
if len(args) and args[0] == "compare":
|
if len(args):
|
||||||
|
if args[0] == "compare":
|
||||||
return p.message(str(compare(args[1], args[2])))
|
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:
|
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:
|
else:
|
||||||
return p.message("{}: An error occurred attempting to find a question.".format(msg.nick))
|
return p.message("{}: An error occurred attempting to find a question.".format(msg.nick))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue