-
Notifications
You must be signed in to change notification settings - Fork 10
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
Collapse long messages into gist command #362
Conversation
futaba/cogs/moderation/core.py
Outdated
@@ -439,3 +439,41 @@ async def unban(self, ctx, user: UserConv, *, reason: str): | |||
raise ManualCheckFailure( | |||
content="I don't have permission to unban this user" | |||
) | |||
|
|||
@commands.command(name="msgcollapse", aliases=["gist"]) |
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.
I had a thought: we could have !gist
create a gist of arbitrary messages kind of like !msg
does, and then have !mvgist
or something that does what this currently performs. Then you have a generic helper method do the actual gist-ing. This can be a separate PR ofc.
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.
Done, since I was splitting the command into a helper function, it might as well be its own command.
futaba/cogs/moderation/core.py
Outdated
# check if the messages were created by the same user | ||
raise ManualCheckFailure(content="I can only collapse your messages") | ||
|
||
logger.info("Collapsing %d messages into a gist", len(messages)) |
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.
Add the guild ID and the user ID requesting it, and possibly the message IDs that were requested as well.
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.
Done.
futaba/cogs/moderation/core.py
Outdated
filename="collapsed.md", | ||
description="Discord collapsed messages", | ||
public=False, | ||
) |
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 mentioned above, I would recommend a generic method on bot
that fills in the arguments that are common
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.
So should I add these & token into settings(cog & sql)? Or maybe move the whole functionality into like an optional cog so that it's distinct from moderation, and would use the optional_cog_settings
table?
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.
This can be in the main cog I think, I'm just suggesting you have a helper method for creating gists. This way it's easier for other parts of the bot in the future to also use it without violating DRY.
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.
Oh ok, I just thought that there might be an issue with storing the github token in the main config because the bot might be used by multiple guilds.
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.
Is it okay that the helper method is also a command? Because otherwise it would just be a passthrough method. I also changed the in-code string literals to configuration options.
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.
futaba is only in 3 guilds, however having the allowing a github token per guild would be fine, lets the guild manage the gists created, a help method was just suggested in case we want other thing to be added to a gist that way it can be managed in one place
Merge upstream changes
…essage(mvgist). Added requested parameters to log.
futaba/cogs/moderation/core.py
Outdated
filename="collapsed.md", | ||
description="Discord collapsed messages", | ||
public=False, | ||
) |
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.
futaba is only in 3 guilds, however having the allowing a github token per guild would be fine, lets the guild manage the gists created, a help method was just suggested in case we want other thing to be added to a gist that way it can be managed in one place
futaba/cogs/moderation/core.py
Outdated
if not self.bot.config.gist_oauth_token: | ||
raise CommandFailed(content="The gist oauth token is not configured.") | ||
|
||
messages_content = "\n".join(str(message.content) for message in messages) |
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.
If this allows multiple messages it would be a good idea to add the username to this so we know who said what and that in the gist
Just moved everything into an optional cog. Will probably need to clean up a bit and squash a whole bunch of commits. |
74e2a7a
to
306fae2
Compare
__all__ = ["create_single_gist"] | ||
|
||
github_api_url = "https://api.github.com/" | ||
github_gist_endpoint = urllib.parse.urljoin(github_api_url, "/gists") |
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.
constants should be SCREAMING_SNAKE_CASE
ctx.guild.id, | ||
) | ||
|
||
embed = discord.Embed(description="Done! Messages successfully uploaded!") |
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.
Bot shouldn't be this excited, I would limit it to a single exclamation point
|
||
await ctx.send(embed=embed) | ||
|
||
@commands.command(name="mvgist", aliases=["msgcollapse"]) |
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.
Also add the full form messagecollapse
and movegist
aliases
# check if the messages were created by the same user | ||
raise ManualCheckFailure(content="I can only collapse your messages") | ||
|
||
await self.upload_message(ctx, *messages) |
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.
Would prefer if this was a common helper method instead of directly invoking another command. If arguments or things involving pre/post command hooks change then this will cause issues.
await self.upload_message(ctx, *messages) | ||
|
||
for message in messages: | ||
await message.delete() |
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.
Parallelize this with asyncio.gather()
This implements collapsing messages into gists as specified in #242.
Added a new file
futaba/gist.py
to keep github/gist api logic in, so that it may be extended later, and to prevent adding an additional dependency for a single feature. I don't know if this is following your convention since it's currently just a single method at the moment.Added a new configuration option under moderation
gist-oauth-token
, since it's a token I thought that would be the correct place for it, but maybe it should be configured db/settings side instead?Anyway sorry about the random PR, I just got carried away a bit and thought that maybe it could be useful.