Pure Pulsars#7
Conversation
ruff check
This just send a message with the answer when the give up button is pressed, it doesn't actually perform any necessary cleanup.
This modifies the original message to not have the buttons when the user gives up the game.
Allows using the `logging` module to pass log messages to discord's default logger. ALSO adds using the environment variable `LOG_LEVEL` to set the logging level, with the current default being INFO. So you can run `LOG_LEVEL=DEBUG python src/main.py` to get a DEBUG-level logging experience.
DEBUG is very messy, and this info is slightly more useful to maintenance than the common DEBUG output
(wiki-guesser) "Give Up" button, logging update
Added commands.bot.tree instead of Client and added a sync command under the prefix of /
Added it for more readable timestamps for the User info command
added it to the user info for an easier piece of info.
made things work. added the on_join event for syncing on join, and also updated the /sync command so we can run it.
| ----- | ||
| Another command, ``/reset-scores``, can be used to reset the scores of | ||
| all users in a server. | ||
| :w |
|
|
||
| Notes: | ||
| ----- | ||
| Another command, ``/reset-scores``, can be used to reset the scores of |
There was a problem hiding this comment.
Is it supposed to have three backticks instead?
|
|
||
| await interaction.followup.send(embed=embed) | ||
| except CommandInvokeError as e: | ||
| logging.info("Leaderboard:\nException: %s", e) |
There was a problem hiding this comment.
I think this should be logging.error instead, also could utilise an f-string
| await interaction.response.defer(thinking=True) | ||
| board = await DATA.get_server(ser_id) | ||
| lead = list(board.values()) | ||
| lead.sort(key=_sort_leaders, reverse=True) |
There was a problem hiding this comment.
I think a lambda would be cleaner, lead.sort(key=lambda user: user.score()) as the function is only being used here.
| board = await DATA.get_server(ser_id) | ||
| lead = list(board.values()) | ||
| lead.sort(key=_sort_leaders, reverse=True) | ||
| lead = lead[0:10] |
There was a problem hiding this comment.
Could we get a comment to explain where 10 comes from?
|
|
||
| COPY . . | ||
|
|
||
| RUN "ls" |
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY requirements.txt requirements.txt |
There was a problem hiding this comment.
Can we move the COPY . . part here and remove this line?
There was a problem hiding this comment.
Ah, this seems to be the correct approach due to how the layers work with building a container.
There was a problem hiding this comment.
What are these cache files needed for?
There was a problem hiding this comment.
I'm not going to review this because its not been implemented
| discord.Embed: The embed message. | ||
|
|
||
| """ | ||
| embed_msg = Embed(title=summary["Title"], description=summary["Intro"], url=summary["URL"], color=0xFFFFFF) |
There was a problem hiding this comment.
Could we add a comment of what the colour is?
| try: | ||
| # Generate a summary and return an embed message | ||
| text = article.extract(intro=False) | ||
| response = model.generate_content(text) |
There was a problem hiding this comment.
This is an interesting way of getting the response from the AI, good catch on the try/except. However, I think there should be a note/warning to the user about the potential miss-information from using a LLM.
| value=user_data["score"], | ||
| inline=False, | ||
| ) | ||
| try: |
There was a problem hiding this comment.
Could we pre-generate the value variable first, instead of using another nested try/except?
value = (user_data["wins"] / user_data["failure"]) if user_data["failure"] > 0 else user_data["wins"]| """Determine animal's weight ranges based on article text.""" | ||
| api_url = f"https://api.api-ninjas.com/v1/animals?name={animal_name}" | ||
| async with ( | ||
| aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=20)) as session, |
There was a problem hiding this comment.
This is quite a long timeout, won't the discord interaction timeout by then? Is it worth reducing it?
| try: | ||
| api_url = "https://en.wikipedia.org/wiki/Special:RandomInCategory?wpcategory=Mammals of the United States" | ||
| async with ( | ||
| aiohttp.ClientSession(headers={"UserAgent": UA}, timeout=aiohttp.ClientTimeout(total=20)) as session, |
| if weight_phrases: | ||
| weight_ranges = [UREG.Quantity(weight) for weight in weight_phrases] | ||
| if len(weight_ranges) % 2 == 0: | ||
| return [weight_ranges[0], weight_ranges[1]] |
There was a problem hiding this comment.
I don't understand the point of this code, why are we checking if its even/odd? Could we adda comment
| loc = str(response.real_url) | ||
| title = loc.split("=")[1].split("&")[0] | ||
| article = await search_wikipedia(title) | ||
| animal_name = article.title().split(" ")[-1] |
There was a problem hiding this comment.
This can error if search_wikipedia doesn't return anything.
| from button_class import ExcerptButton, GiveUpButton, GuessButton, LinkListButton, _Button, _Ranked | ||
| from wikiutils import make_embed, rand_wiki, win_update | ||
|
|
||
| ACCURACY_THRESHOLD = 0.8 |
| await interaction.followup.send(content=msg, embed=embed) | ||
| if ranked: | ||
| user = interaction.user | ||
| for i in [interaction.guild_id, 0]: |
|
|
||
| excerpt = article.extract(chars=1200) | ||
|
|
||
| for i in article.title().split(): |
There was a problem hiding this comment.
Will this censor the word if its in FULL UPPERCASE?
| excerpt = excerpt.replace(i, "~~CENSORED~~") | ||
| excerpt = excerpt.replace(i.lower(), "~~CENSORED~~") | ||
|
|
||
| sentances = [i for i in excerpt.strip("\n").split(".") if i] |
There was a problem hiding this comment.
*sentences, I think we could have a better variable name than i - and a comment?
| self._default_app = firebase_admin.initialize_app( | ||
| cred_obj, | ||
| { | ||
| "databaseURL": "https://pure-pulsars-default-rtdb.firebaseio.com/", |
| NullUserError: If the user doesn't exist. | ||
|
|
||
| """ | ||
| """self._ref = db.reference("/users")""" |
|
|
||
|
|
||
| # activates the commands | ||
| sync.main(client.tree) |
There was a problem hiding this comment.
Is there a better way to do this then all these lines?
| """ | ||
| result = Page(site, title=query) | ||
|
|
||
| if not result.exists() or result.isRedirectPage(): |
There was a problem hiding this comment.
Does the redirect page take you to to article?
| return get_best_result(results, query) | ||
|
|
||
| try: | ||
| return result |
| await DATA.add_user(uid, new_user, guild) | ||
|
|
||
|
|
||
| async def win_update(guild: int, user: User, score: int) -> None: |
There was a problem hiding this comment.
Would it be better to have a single update function which you can the pass in in the win/loss argument instead of having two functions?
| articles = [article for article in articles if self.article_has_categories(article)] | ||
|
|
||
| try: | ||
| return articles |
| articles = {a for articles in title_articles.values() for a in articles} | ||
|
|
||
| if any(article is None for article in title_articles.values()): | ||
| titles_not_found = [title for title, article in title_articles.items() if article is None] | ||
| message = f"No articles found for the following titles: {titles_not_found}" | ||
|
|
||
| raise ArticleGeneratorError(message) |
|
Hey everyone, fantastic project! The logo and website added a great personalised touch, and setting up the bot was a breeze. I've done a review of the codebase, and had a play around with the features - here are my thoughts on what I liked and what could be improved on. Project overview
Commit overview
Codebase overview
Usage overview
discord.app_commands.errors.CommandInvokeError: Command 'wiki-animal' raised an exception: AttributeError: 'NoneType' object has no attribute 'title'
discord.app_commands.errors.CommandInvokeError: Command 'leaderboard' raised an exception: AttributeError: 'NoneType' object has no attribute 'values
Other
|
No description provided.