-
-
Notifications
You must be signed in to change notification settings - Fork 256
Add "math" and "science" categories to the .quiz
command (and more in desc)
#726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add 30 math questions and 30 science questions to trivia_quiz.json
Implement the math and science questions, added a dynamic_id checker
Add dynamic question formatters and its constants
converting to draft because i have to fix some linting fails |
all lint failures fixed, ready for review! |
REGARDING THE CS AND PYTHON QUESTIONS: We... just didn't get that much questions, so I didn't add them into the database. Our list can be found here, and once we get 30 questions on each I might open a new PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, tested and works good
.quiz
command..quiz
command (and more in desc)
Co-authored-by: Anand Krishna <[email protected]>
Co-authored-by: ToxicKidz <[email protected]>
Co-authored-by: ToxicKidz <[email protected]>
Co-authored-by: ToxicKidz <[email protected]>
backend? i'm adding more stuff for user features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a pure code review, this looks good to me
woohoo |
self.bot = bot | ||
self.questions = self.load_questions() | ||
|
||
self.game_status = {} # A variable to store the game status: either running or not running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's not very good that we have a piece of code nobody can understand. Code should be understandable by those who read it. If it's not, you should investigate and fix it.
From what I was able to gather from the code, game_status
is a dict that maps a channel ID to a boolean flag. Its purpose is to make sure that at most one quiz is present in a channel, but to allow multiple quizzes in multiple channels.
So this is what I would do:
self.is_game_running: Dict[int, bool] = {} # maps channel ID to whether a quiz is running in that channel
Now, you also have two other variables:
self.game_owners = {} # A variable to store the person's ID who started the quiz game in a channel.
self.player_scores = {} # A variable to store all player's scores for a bot session.
self.game_player_scores = {} # A variable to store temporary game player's scores.
Do you see a pattern? All these 4 dicts take a channel ID and return a game state. So what you could do is put all that into one object:
class Game:
def __init__(self, owner_id: int):
self.owner_id = owner_id
self._scores: Dict[int, int] = {}
def add_score(self, player_id: int, score_delta: int) -> None:
self._scores[player_id] = self._scores.get(player_id, 0) + score_delta
def player_scores(self) -> Sequence[Tuple[int, int]]:
"""Returns a list of (user_id, score) tuples"""
return list(self._scores.items())
inside the Cog class:
self.games: Dict[int, Game] = {} # maps channel ID to its current game
self.player_scores
is actually not used at all (double-check, but it seems so), so remove it.
except for the major refactoring, which would probably be in a separate pr
smh i have to stop making these errors lmao, definitely going to see that precommit thing after this
@decorator-factory your changes have all been implemented (except for major refactoring) :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@Objectivitix please resolve these conflicts. |
@Xithrius All conflicts have been resolved. Two are caused by the spring cleanup I believe, and so I selected the spring cleanup ones |
Thank you, I'll do a final test and then give my thoughts. Code looks good to me as of now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works well.
ZETAPOGGERS |
Relevant Issues
Closes #719
Description & Implementation
TL;DR - added multiple possible answers, images, dynamically generated questions and two new categories (60 questions in total)
PART ONE:
After gathering a database of questions and answers, I incorporated them into the json file. Some questions requiring images are supplemented with an "img_url" entry, and some requiring dynamic generation (e.g. Math Q1, a random system of linear equations with two unknowns) have an "dynamic_id" entry, which will come into use later.
PART TWO:
"math"
and"science"
! Also fixed some original flaws in the code so the abandoned category "retro" can function properly. Updated the documentation string in quiz_game to include these categories.fuzz
) they will all be correct. These correct answers will also be listed in the answer embed (send_answer
), and are separated by commas in the json file."img_url"
entry) in the quiz_game method..quiz <category> <questions>
. Also changed the default from 5 questions to 8 questions. Added error embeds which will be sent when questions is larger than the amount of questions in that category, or if it's less than0
(0 just makes it default).PART THREE:
This is where all the dynamic questions come to life! Each dynamic question has an unique "dynamic_id", which corresponds to a function taking its "question" and "answer" as input, formats them, and returns them in a tuple. This is how the questions will be dynamically generated.
Images
Normal Q&A
Dynamically generated question
Question with image
Error embeds
Did you: