add rollcall, various bugfixes
This commit is contained in:
parent
67ef8e6a1e
commit
01adc3d6b7
|
@ -101,3 +101,7 @@ ENV/
|
|||
.mypy_cache/
|
||||
|
||||
jeopardy.db
|
||||
tildechat.py
|
||||
maddshark.py
|
||||
localhost.py
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
from pinhook.bot import Bot
|
||||
|
||||
bot = Bot(
|
||||
channels=['#aaa', '#counting', '#counting-meta', '#counting-anarchy', '#bots'],
|
||||
channels=['#counting', '#counting-meta', '#counting-anarchy', '#bots'],
|
||||
nickname='lurch',
|
||||
server='localhost',
|
||||
ops=['kirch']
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pinhook.plugin as p, re
|
||||
import pinhook.plugin as p
|
||||
import re
|
||||
import urllib.request as http
|
||||
import json
|
||||
import operator
|
||||
|
@ -17,7 +18,7 @@ alex = {
|
|||
"incorrect": ["I'm sorry, that is incorrect", "That's not it", "Good guess", "Close"],
|
||||
"correction": ["I think you mean", "Actually, the correct answer is", "The correct answer is"]
|
||||
}
|
||||
formquestion_rex = re.compile(r'(?:\b(who|what|where|when|why|how)\b\s+\b(is|was|are|were)\b\s+)?(?P<answer>.*)\??')
|
||||
formquestion_rex = re.compile(r'(?:\b(who|what|where|when|why|how)\b\s+\b(is|was|are|were)\b\s+)?(?P<answer>[^?]+)\??', re.I)
|
||||
html = re.compile(r'<[^>]+>')
|
||||
|
||||
def leaderboard(chan):
|
||||
|
@ -37,7 +38,7 @@ def leaderboard(chan):
|
|||
|
||||
def score(msg, points):
|
||||
s = shelve.open('jeopardy.db', writeback=True)
|
||||
key = str(msg.nick + msg.channel + msg.server)
|
||||
key = str(msg.nick + msg.channel + msg.bot.servers[0].host)
|
||||
if points:
|
||||
if key in s:
|
||||
s[key] = int(s[key]) + int(points)
|
||||
|
@ -64,17 +65,17 @@ def compare(guess, answer):
|
|||
tally += item[0]
|
||||
average = tally / len(metric)
|
||||
print("answer: " + answer + " || guess: " + guess + " || match: " + str(average))
|
||||
if average > 0.4:
|
||||
if average > 0.45:
|
||||
return True
|
||||
|
||||
|
||||
def markinvalid(msg):
|
||||
key = (msg.nick, msg.channel, msg.server)
|
||||
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.server)]
|
||||
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:
|
||||
|
@ -89,36 +90,37 @@ def getquestion(msg):
|
|||
try:
|
||||
if data:
|
||||
data = choice( list( (d for d in data if d['invalid_count'] == None and d['value'] != None) ) )
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)] = {}
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["q"] = data["question"].encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["answer"] = re.sub(html, '', data["answer"]).encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["cat"] = data["category"]["title"].encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["points"] = data["value"]
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["id"] = data["id"]
|
||||
return jeopardy_tmp[(msg.nick, msg.channel, msg.server)]
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)] = {}
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["q"] = data["question"].encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["answer"] = re.sub(html, '', data["answer"]).encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["cat"] = data["category"]["title"].encode('utf-8').decode('unicode_escape')
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["points"] = data["value"]
|
||||
jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["id"] = data["id"]
|
||||
return jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
@p.listener('jeopardy_reply')
|
||||
def jeopardyreply(msg):
|
||||
if (msg.nick, msg.channel, msg.server) in jeopardy_tmp:
|
||||
answer = jeopardy_tmp[(msg.nick, msg.channel, msg.server)]["answer"]
|
||||
if (msg.nick, msg.channel, msg.bot.servers[0].host) in jeopardy_tmp:
|
||||
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")
|
||||
guess = guess.group("answer")
|
||||
else:
|
||||
print("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.server)]["points"]
|
||||
points = jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]["points"]
|
||||
if points:
|
||||
msg.privmsg(msg.channel, "{}, {}. You get {} points for \"{}\", this brings your total score to: {}".format(choice(alex["correct"]), msg.nick, points, answer, score(msg, points)))
|
||||
else:
|
||||
msg.privmsg(msg.channel, "{}, {}. It's {}.".format(choice(alex["correct"]), msg.nick, answer))
|
||||
else:
|
||||
msg.privmsg(msg.channel, "{}, {}. {}: {}.".format(choice(alex["incorrect"]), msg.nick,choice(alex["correction"]), answer))
|
||||
del jeopardy_tmp[(msg.nick, msg.channel, msg.server)]
|
||||
|
||||
del jeopardy_tmp[(msg.nick, msg.channel, msg.bot.servers[0].host)]
|
||||
|
||||
@p.register('!j', 'Ask a Jeopardy Question')
|
||||
@p.register('!jeopardy', 'Ask a Jeopardy Question')
|
||||
|
@ -138,7 +140,7 @@ def jeopardy(msg):
|
|||
|
||||
output = getquestion(msg)
|
||||
if output:
|
||||
return p.message("The Category is '{}'. {}: {}".format(output["cat"], choice(alex["ask"]), output["q"]))
|
||||
return p.message("{}: The Category is '{}'. {}: {}".format(msg.nick, output["cat"], choice(alex["ask"]), output["q"]))
|
||||
else:
|
||||
return p.message("An error occurred attempting to find a question.")
|
||||
return p.message("{}: An error occurred attempting to find a question.".format(msg.nick))
|
||||
|
||||
|
|
|
@ -8,9 +8,7 @@ A plugin for monitoring a channel and finding Numberwangs.
|
|||
|
||||
@p.listener('numberwang')
|
||||
def numberwang(msg):
|
||||
global digit_count
|
||||
global wang_count
|
||||
if re.compile("[0-9a-fx]", re.I).match(msg.text):
|
||||
if re.compile("[0-9a-fx]+", re.I).match(msg.text):
|
||||
if random.randint(0,100) == 0:
|
||||
return p.message("CONGRATS {}! THAT'S NUMBERWANG!".format(msg.nick))
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import pinhook.plugin as p
|
||||
|
||||
|
||||
@p.register('!rollcall')
|
||||
def rollcall(msg):
|
||||
admins = "Admin"
|
||||
if len(msg.ops) > 1:
|
||||
admins = admins + "s"
|
||||
admins = admins + ": " + ', '.join(msg.ops)
|
||||
commands = 'Available commands: ' + ''.join([i + ', ' for i in p.cmds.keys()]).strip(', ')
|
||||
return p.message(commands + '; ' + admins)
|
Loading…
Reference in New Issue