forked from Raka-loah/Paarthurnax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trivia.py
66 lines (47 loc) · 1.69 KB
/
trivia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import os
import random
import requests
import time
new_question_keyword = '/出题'
curr = {}
questions = {}
with open(os.path.dirname(os.path.abspath(__file__)) + '\\data\\cet4.json', 'r', encoding='utf-8') as E:
questions = json.loads(E.read())
score = {}
def new_question():
pass
def check_answer(answer):
pass
def get_score(user_id=0):
# when user_id == 0 return all players' score
pass
def generate_hint(answer):
pass
def triviabot(j):
# Ignore messages with no group_id
# Double check because I'm paranoid
if 'group_id' not in j:
return ''
# Someone wanted a new question
if j['message'] == new_question_keyword:
# Initialize dict
if j['group_id'] not in curr:
curr[j['group_id']] = {
'state': 0
}
# Send a new question if state 0
# Send old question if else
if curr[j['group_id']]['state'] == 0:
question = random.sample(list(questions), k=1).pop()
curr[j['group_id']]['question'] = '请根据音标和含义写出对应英文单词:\n{}\n{}'.format(questions[question][0], questions[question][1])
curr[j['group_id']]['answer'] = question
curr[j['group_id']]['time'] = time.time()
curr[j['group_id']]['state'] = 1
return curr[j['group_id']]['question']
# If a question stays unanswered
if j['group_id'] in curr and curr[j['group_id']]['state'] == 1:
if j['message'].lower().strip() == curr[j['group_id']]['answer'].lower().strip():
curr[j['group_id']]['state'] = 0
return '[CQ:at,qq={}]:\n回答正确!'.format(j['sender']['user_id'])
return ''