forked from eduardafneumann/discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
135 lines (102 loc) · 3.35 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import pandas as pd
import asyncio
import json
load_dotenv()
with open('config.json') as config_file:
config = json.load(config_file)
DISCORD_TOKEN = config['DISCORD_TOKEN']
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=">>", intents=intents)
#leitura dos dados
df = pd.read_csv('in.csv', sep='|')
dataBase = [(topics, question, answers) for topics, question, answers in zip(df.topics, df.questions, df.answers)]
topicsToString = [
"Introdução",
"Arquitetura RISC-V: Assembly",
"Arquitetura RISC-V: Monociclo",
"Arquitetura RISC-V: Pipeline",
"Hierarquia de Memória",
"Entrada e Saída",
"Barramento"
]
topics = [
"Introducao",
"Assembly",
"Monociclo",
"Pipeline",
"Hierarquia",
"ES",
"Barramento"
]
@bot.event
async def on_ready():
print("Bot is online!")
@bot.command(
aliases = ['questions','exercicios'],
help = "Example:\n >>perguntas",
brief = "Study material",
description = "Gives the user study material for the course",
enabled = True,
hidden = False
)
async def perguntas(message):
"""Gives the user the option to choose the desired topic of the questions"""
embed = discord.Embed(
colour = discord.Colour.dark_teal(),
description = """1. Introdução
2. Arquitetura RISC-V: Assembly
3. Arquitetura RISC-V: Monociclo
4. Arquitetura RISC-V: Pipeline
5. Hierarquia de Memória
6. Entrada e Saída
7. Barramento
Use >>cancelar para sair!""",
title = f"Olá **{message.author.global_name}**! Qual tópico você quer estudar?"
)
embed.set_footer(text="Organização e Arquitetura de Computadores\nCriado por Eduarda Neumann, Luís Henrique Dantas, João Gabriel Nazar")
await message.send(embed=embed)
def check(m):
if m.content == ">>cancelar":
return True
return m.content.isdigit() and int(m.content) in range(1, 8) and m.channel == message.channel
try:
msg = await bot.wait_for('message', check=check)
if msg.content == ">>cancelar":
await message.send("Comando cancelado.")
return
except asyncio.TimeoutError:
await message.send("Tempo esgotado. Comando 'perguntas' cancelado.")
return
#Gets questions and answers
counter = 0
questions = []
answers = []
for topic, question, answer in dataBase:
if topic == topics[int(msg.content)-1]:
questions.append(question)
answers.append(answer)
counter += 1
#Sends user the questions in DM
if len(questions) != 0:
await message.author.send(f"""Aqui estão **{counter}** questões sobre o tópico **{topicsToString[int(msg.content)-1]}** da disciplina de Organização e Arquitetura de Computadores!
# Questões\n\n""")
for i, (question,answer) in enumerate(zip(questions,answers)):
embed = discord.Embed(
colour = discord.Colour.dark_teal(),
description = f"{question}\n\n *Gabarito:*\n ||```{answer}```||",
title = f"__**Questão {i+1}**__"
)
await message.author.send(embed=embed)
await message.author.send("""## \n\nTem dúvidas? Entre em contato com um monitor ou com a professora Sarita!\n
**Contatos:**
__E-mail:__ [email protected]
__Discord:__ @Sarita - ICMC/USP (No Grupo da disciplina)""")
else:
await message.author.send("Não tenho questões desse tópico disponíveis.")
return
bot.run(DISCORD_TOKEN)