-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (77 loc) · 3.07 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import discord
import os
import random
from replit import db
from pingtorun import keep_alive
previousnum = 1000
fhandle = open('question.txt')
status = 0
answer = ''
client = discord.Client()
@client.event
async def on_ready() :
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message) :
if message.author == client.user:
return
if message.content.startswith('$trivia') :
global previousnum
global status
global answer
status = 1
question = ''
outercount = 0
num = random.randint(0, 29)
while previousnum == num:
num = random.randint(0, 29)
previousnum = num
fhandle.seek(0, 0)
for line in fhandle:
outercount = outercount + 1
if (6*num) < outercount < (6*num + 6):
question = question + line
if (6*num + 6) == outercount:
answer = line.rstrip()
await message.channel.send(question.rstrip())
if message.content.startswith('$answer') :
if status == 0:
await message.channel.send("This Question Has Already Been Answered")
else:
idt = str(message.author.id)
useranswer = message.content.split("$answer ")[1]
if idt in db:
print('')
else:
db[idt] = 0
if useranswer == answer:
status = 0
await message.channel.send("You're Correct Great Job")
db[idt] += 1
else:
await message.channel.send("You Are Incorrect")
if message.content.startswith('$score'):
embed = discord.Embed(color = discord.Colour.green())
embed.set_author(name = 'Score')
for comp in db.keys():
temporaryid = await client.fetch_user(int(comp))
embed.add_field(name = temporaryid, value = db[comp])
await message.channel.send(embed=embed)
if message.content.startswith('$end'):
embed = discord.Embed(color = discord.Colour.green())
embed.set_author(name = 'Results')
for comp in db.keys():
temporaryid = await client.fetch_user(int(comp))
embed.add_field(name = temporaryid, value = db[comp])
await message.channel.send(embed=embed)
db.clear()
if message.content.startswith('$commands'):
embed = discord.Embed(color = discord.Colour.green())
embed.set_author(name = 'Commands')
embed.add_field(name = '$trivia', value = 'displays a question with four options a,b,c,d', inline = False)
embed.add_field(name = '$answer', value = 'allows a user to answer a question displayed using $trivia', inline = False)
embed.add_field(name = '$score', value = 'displays the score of users who have answered questions', inline = False)
embed.add_field(name = '$end', value = 'displays final score of users who have answered a question and clears score data', inline = False)
await message.channel.send(embed=embed)
keep_alive()
client.run(os.getenv('TOKEN'))