Merge pull request #111 from bobloy/maybe_send_embeds

Use maybe_send_embed instead
Now's a good a time as any
pull/122/head
bobloy 4 years ago committed by GitHub
commit 3d4a6578fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -113,7 +113,7 @@ class Chatter(Cog):
for channel in ctx.guild.text_channels: for channel in ctx.guild.text_channels:
if in_channel: if in_channel:
channel = in_channel channel = in_channel
await ctx.send("Gathering {}".format(channel.mention)) await ctx.maybe_send_embed("Gathering {}".format(channel.mention))
user = None user = None
i = 0 i = 0
send_time = after - timedelta(days=100) # Makes the first message a new message send_time = after - timedelta(days=100) # Makes the first message a new message
@ -194,7 +194,7 @@ class Chatter(Cog):
""" """
if not confirm: if not confirm:
await ctx.send( await ctx.maybe_send_embed(
"Warning, this command will erase all your training data and reset your configuration\n" "Warning, this command will erase all your training data and reset your configuration\n"
"If you want to proceed, run the command again as `[p]chatter cleardata True`" "If you want to proceed, run the command again as `[p]chatter cleardata True`"
) )
@ -320,7 +320,7 @@ class Chatter(Cog):
Backup your training data to a json for later use Backup your training data to a json for later use
""" """
await ctx.send("Backing up data, this may take a while") await ctx.maybe_send_embed("Backing up data, this may take a while")
path: pathlib.Path = cog_data_path(self) path: pathlib.Path = cog_data_path(self)
@ -331,9 +331,9 @@ class Chatter(Cog):
) )
if future: if future:
await ctx.send(f"Backup successful! Look in {path} for your backup") await ctx.maybe_send_embed(f"Backup successful! Look in {path} for your backup")
else: else:
await ctx.send("Error occurred :(") await ctx.maybe_send_embed("Error occurred :(")
@chatter.command(name="trainubuntu") @chatter.command(name="trainubuntu")
async def chatter_train_ubuntu(self, ctx: commands.Context, confirmation: bool = False): async def chatter_train_ubuntu(self, ctx: commands.Context, confirmation: bool = False):
@ -365,9 +365,9 @@ class Chatter(Cog):
future = await self.loop.run_in_executor(None, self._train_english) future = await self.loop.run_in_executor(None, self._train_english)
if future: if future:
await ctx.send("Training successful!") await ctx.maybe_send_embed("Training successful!")
else: else:
await ctx.send("Error occurred :(") await ctx.maybe_send_embed("Error occurred :(")
@chatter.command() @chatter.command()
async def train(self, ctx: commands.Context, channel: discord.TextChannel): async def train(self, ctx: commands.Context, channel: discord.TextChannel):
@ -375,7 +375,7 @@ class Chatter(Cog):
Trains the bot based on language in this guild Trains the bot based on language in this guild
""" """
await ctx.send( await ctx.maybe_send_embed(
"Warning: The cog may use significant RAM or CPU if trained on large data sets.\n" "Warning: The cog may use significant RAM or CPU if trained on large data sets.\n"
"Additionally, large sets will use more disk space to save the trained data.\n\n" "Additionally, large sets will use more disk space to save the trained data.\n\n"
"If you experience issues, clear your trained data and train again on a smaller scope." "If you experience issues, clear your trained data and train again on a smaller scope."
@ -385,10 +385,10 @@ class Chatter(Cog):
conversation = await self._get_conversation(ctx, channel) conversation = await self._get_conversation(ctx, channel)
if not conversation: if not conversation:
await ctx.send("Failed to gather training data") await ctx.maybe_send_embed("Failed to gather training data")
return return
await ctx.send( await ctx.maybe_send_embed(
"Gather successful! Training begins now\n" "Gather successful! Training begins now\n"
"(**This will take a long time, be patient. See console for progress**)" "(**This will take a long time, be patient. See console for progress**)"
) )
@ -403,9 +403,9 @@ class Chatter(Cog):
pass pass
if future: if future:
await ctx.send("Training successful!") await ctx.maybe_send_embed("Training successful!")
else: else:
await ctx.send("Error occurred :(") await ctx.maybe_send_embed("Error occurred :(")
@commands.Cog.listener() @commands.Cog.listener()
async def on_message_without_command(self, message: discord.Message): async def on_message_without_command(self, message: discord.Message):

@ -39,7 +39,7 @@ class CogLint(Cog):
self.do_lint = not curr self.do_lint = not curr
await self.config.lint.set(not curr) await self.config.lint.set(not curr)
await ctx.send("Autolinting is now set to {}".format(not curr)) await ctx.maybe_send_embed("Autolinting is now set to {}".format(not curr))
@commands.command() @commands.command()
async def lint(self, ctx: commands.Context, *, code): async def lint(self, ctx: commands.Context, *, code):
@ -48,7 +48,7 @@ class CogLint(Cog):
Toggle autolinting with `[p]autolint` Toggle autolinting with `[p]autolint`
""" """
await self.lint_message(ctx.message) await self.lint_message(ctx.message)
await ctx.send("Hello World") await ctx.maybe_send_embed("Hello World")
async def lint_code(self, code): async def lint_code(self, code):
self.counter += 1 self.counter += 1

@ -46,7 +46,7 @@ class Flag(Cog):
"""Clears all flags for all members in this server""" """Clears all flags for all members in this server"""
await self.config.guild(ctx.guild).flags.clear() await self.config.guild(ctx.guild).flags.clear()
await ctx.send("Done") await ctx.maybe_send_embed("Done")
@checks.mod_or_permissions(manage_roles=True) @checks.mod_or_permissions(manage_roles=True)
@commands.guild_only() @commands.guild_only()
@ -66,7 +66,7 @@ class Flag(Cog):
Set the number of days for flags to expire after for server Set the number of days for flags to expire after for server
""" """
await self.config.guild(ctx.guild).days.set(days) await self.config.guild(ctx.guild).days.set(days)
await ctx.send("Number of days for new flags to expire is now {} days".format(days)) await ctx.maybe_send_embed("Number of days for new flags to expire is now {} days".format(days))
@flagset.command(name="dm") @flagset.command(name="dm")
async def flagset_dm(self, ctx: commands.Context): async def flagset_dm(self, ctx: commands.Context):
@ -75,7 +75,7 @@ class Flag(Cog):
dm = await self.config.guild(ctx.guild).dm() dm = await self.config.guild(ctx.guild).dm()
await self.config.guild(ctx.guild).dm.set(not dm) await self.config.guild(ctx.guild).dm.set(not dm)
await ctx.send("DM-ing members when they get a flag is now set to **{}**".format(not dm)) await ctx.maybe_send_embed("DM-ing members when they get a flag is now set to **{}**".format(not dm))
@staticmethod @staticmethod
def _flag_template(): def _flag_template():
@ -114,9 +114,9 @@ class Flag(Cog):
try: try:
await member.send(embed=outembed) await member.send(embed=outembed)
except discord.Forbidden: except discord.Forbidden:
await ctx.send("DM-ing user failed") await ctx.maybe_send_embed("DM-ing user failed")
else: else:
await ctx.send("This member has no flags.. somehow..") await ctx.maybe_send_embed("This member has no flags.. somehow..")
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_roles=True) @checks.mod_or_permissions(manage_roles=True)
@ -128,7 +128,7 @@ class Flag(Cog):
await self.config.guild(guild).flags.set_raw(str(member.id), value=[]) await self.config.guild(guild).flags.set_raw(str(member.id), value=[])
await ctx.send("Success!") await ctx.maybe_send_embed("Success!")
@commands.guild_only() @commands.guild_only()
@commands.command(aliases=["flaglist"]) @commands.command(aliases=["flaglist"])
@ -142,7 +142,7 @@ class Flag(Cog):
if outembed: if outembed:
await ctx.send(embed=outembed) await ctx.send(embed=outembed)
else: else:
await ctx.send("This member has no flags!") await ctx.maybe_send_embed("This member has no flags!")
@commands.guild_only() @commands.guild_only()
@commands.command(aliases=["flagall"]) @commands.command(aliases=["flagall"])

@ -159,19 +159,19 @@ class Hangman(Cog):
theface = self.bot.get_emoji(int(theface.split(":")[2][:-1])) theface = self.bot.get_emoji(int(theface.split(":")[2][:-1]))
if theface is None: if theface is None:
await ctx.send("I could not find that emoji") await ctx.maybe_send_embed("I could not find that emoji")
return return
try: try:
# Use the face as reaction to see if it's valid (THANKS FLAPJACK <3) # Use the face as reaction to see if it's valid (THANKS FLAPJACK <3)
await message.add_reaction(theface) await message.add_reaction(theface)
except discord.errors.HTTPException: except discord.errors.HTTPException:
await ctx.send("That's not an emoji I recognize.") await ctx.maybe_send_embed("That's not an emoji I recognize.")
return return
await self.config.guild(ctx.guild).theface.set(str(theface)) await self.config.guild(ctx.guild).theface.set(str(theface))
await self._update_hanglist() await self._update_hanglist()
await ctx.send("Face has been updated!") await ctx.maybe_send_embed("Face has been updated!")
@hangset.command() @hangset.command()
async def toggleemoji(self, ctx: commands.Context): async def toggleemoji(self, ctx: commands.Context):
@ -179,26 +179,26 @@ class Hangman(Cog):
current = await self.config.guild(ctx.guild).emojis() current = await self.config.guild(ctx.guild).emojis()
await self.config.guild(ctx.guild).emojis.set(not current) await self.config.guild(ctx.guild).emojis.set(not current)
await ctx.send("Emoji Letter reactions have been set to {}".format(not current)) await ctx.maybe_send_embed("Emoji Letter reactions have been set to {}".format(not current))
@commands.command(aliases=["hang"]) @commands.command(aliases=["hang"])
async def hangman(self, ctx, guess: str = None): async def hangman(self, ctx, guess: str = None):
"""Play a game of hangman against the bot!""" """Play a game of hangman against the bot!"""
if guess is None: if guess is None:
if self.the_data[ctx.guild]["running"]: if self.the_data[ctx.guild]["running"]:
await ctx.send("Game of hangman is already running!\nEnter your guess!") await ctx.maybe_send_embed("Game of hangman is already running!\nEnter your guess!")
await self._printgame(ctx.channel) await self._printgame(ctx.channel)
"""await self.bot.send_cmd_help(ctx)""" """await self.bot.send_cmd_help(ctx)"""
else: else:
await ctx.send("Starting a game of hangman!") await ctx.maybe_send_embed("Starting a game of hangman!")
self._startgame(ctx.guild) self._startgame(ctx.guild)
await self._printgame(ctx.channel) await self._printgame(ctx.channel)
elif not self.the_data[ctx.guild]["running"]: elif not self.the_data[ctx.guild]["running"]:
await ctx.send("Game of hangman is not yet running!\nStarting a game of hangman!") await ctx.maybe_send_embed("Game of hangman is not yet running!\nStarting a game of hangman!")
self._startgame(ctx.guild) self._startgame(ctx.guild)
await self._printgame(ctx.channel) await self._printgame(ctx.channel)
else: else:
await ctx.send("Guess by reacting to the message") await ctx.maybe_send_embed("Guess by reacting to the message")
# await self._guessletter(guess, ctx.channel) # await self._guessletter(guess, ctx.channel)
def _startgame(self, guild): def _startgame(self, guild):

@ -33,7 +33,7 @@ class Leaver(Cog):
"""Choose the channel to send leave messages to""" """Choose the channel to send leave messages to"""
guild = ctx.guild guild = ctx.guild
await self.config.guild(guild).channel.set(ctx.channel.id) await self.config.guild(guild).channel.set(ctx.channel.id)
await ctx.send("Channel set to " + ctx.channel.name) await ctx.maybe_send_embed("Channel set to " + ctx.channel.name)
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_remove(self, member: discord.Member): async def on_member_remove(self, member: discord.Member):

@ -60,7 +60,7 @@ class LastSeen(Cog):
enabled = not await self.config.guild(ctx.guild).enabled() enabled = not await self.config.guild(ctx.guild).enabled()
await self.config.guild(ctx.guild).enabled.set(enabled) await self.config.guild(ctx.guild).enabled.set(enabled)
await ctx.send( await ctx.maybe_send_embed(
"Seen for this server is now {}".format("Enabled" if enabled else "Disabled") "Seen for this server is now {}".format("Enabled" if enabled else "Disabled")
) )
@ -75,7 +75,7 @@ class LastSeen(Cog):
else: else:
last_seen = await self.config.member(member).seen() last_seen = await self.config.member(member).seen()
if last_seen is None: if last_seen is None:
await ctx.send(embed=discord.Embed(description="I've never seen this user")) await ctx.maybe_send_embed(embed=discord.Embed(description="I've never seen this user"))
return return
last_seen = self.get_date_time(last_seen) last_seen = self.get_date_time(last_seen)

@ -48,7 +48,7 @@ class QRInvite(Cog):
invite = await ctx.channel.invites() invite = await ctx.channel.invites()
invite = invite[0] invite = invite[0]
except discord.Forbidden: except discord.Forbidden:
await ctx.send("No permission to get an invite, please provide one") await ctx.maybe_send_embed("No permission to get an invite, please provide one")
return return
invite = invite.code invite = invite.code
@ -56,7 +56,7 @@ class QRInvite(Cog):
image_url = str(ctx.guild.icon_url) image_url = str(ctx.guild.icon_url)
if image_url == "": # Still if image_url == "": # Still
await ctx.send( await ctx.maybe_send_embed(
"Could not get an image, please provide one. *(`{}help qrinvite` for details)*".format( "Could not get an image, please provide one. *(`{}help qrinvite` for details)*".format(
ctx.prefix ctx.prefix
) )
@ -77,12 +77,12 @@ class QRInvite(Cog):
if extension == "webp": if extension == "webp":
new_path = convert_webp_to_png(str(image_path)) new_path = convert_webp_to_png(str(image_path))
elif extension == "gif": elif extension == "gif":
await ctx.send("gif is not supported yet, stay tuned") await ctx.maybe_send_embed("gif is not supported yet, stay tuned")
return return
elif extension == "png": elif extension == "png":
new_path = str(image_path) new_path = str(image_path)
else: else:
await ctx.send(f"{extension} is not supported yet, stay tuned") await ctx.maybe_send_embed(f"{extension} is not supported yet, stay tuned")
return return
myqr.run( myqr.run(

@ -213,7 +213,7 @@ class ReactRestrict(Cog):
""" """
message = await self._get_message(ctx, message_id) message = await self._get_message(ctx, message_id)
if message is None: if message is None:
await ctx.send("That message doesn't seem to exist.") await ctx.maybe_send_embed("That message doesn't seem to exist.")
return return
# try: # try:
@ -232,7 +232,7 @@ class ReactRestrict(Cog):
# noinspection PyTypeChecker # noinspection PyTypeChecker
await self.add_reactrestrict(message_id, role) await self.add_reactrestrict(message_id, role)
await ctx.send("Message|Role combo added.") await ctx.maybe_send_embed("Message|Role combo added.")
@reactrestrict.command() @reactrestrict.command()
async def remove(self, ctx: commands.Context, message_id: int, role: discord.Role): async def remove(self, ctx: commands.Context, message_id: int, role: discord.Role):

@ -104,14 +104,14 @@ class StealEmoji(Cog):
if not curr_setting: if not curr_setting:
await self.config.notify.set(1) await self.config.notify.set(1)
await ctx.send("Bot owner will now be notified when an emoji is stolen") await ctx.maybe_send_embed("Bot owner will now be notified when an emoji is stolen")
elif curr_setting == 1: elif curr_setting == 1:
channel: discord.TextChannel = ctx.channel channel: discord.TextChannel = ctx.channel
await self.config.notify.set(channel.id) await self.config.notify.set(channel.id)
await ctx.send("This channel will now be notified when an emoji is stolen") await ctx.maybe_send_embed("This channel will now be notified when an emoji is stolen")
else: else:
await self.config.notify.set(0) await self.config.notify.set(0)
await ctx.send("Notifications are now off") await ctx.maybe_send_embed("Notifications are now off")
@checks.is_owner() @checks.is_owner()
@stealemoji.command(name="collect") @stealemoji.command(name="collect")
@ -122,7 +122,7 @@ class StealEmoji(Cog):
self.is_on = await self.config.on() self.is_on = await self.config.on()
await ctx.send("Collection is now " + str(not curr_setting)) await ctx.maybe_send_embed("Collection is now " + str(not curr_setting))
@checks.is_owner() @checks.is_owner()
@commands.guild_only() @commands.guild_only()
@ -140,12 +140,12 @@ class StealEmoji(Cog):
already_a_guildbank = ctx.guild.id in (await self.config.guildbanks()) already_a_guildbank = ctx.guild.id in (await self.config.guildbanks())
if already_a_guildbank: if already_a_guildbank:
await ctx.send( await ctx.maybe_send_embed(
"This is already an emoji bank\n" "This is already an emoji bank\n"
"Are you sure you want to remove the current server from the emoji bank list? (y/n)" "Are you sure you want to remove the current server from the emoji bank list? (y/n)"
) )
else: else:
await ctx.send( await ctx.maybe_send_embed(
"This will upload custom emojis to this server\n" "This will upload custom emojis to this server\n"
"Are you sure you want to make the current server an emoji bank? (y/n)" "Are you sure you want to make the current server an emoji bank? (y/n)"
) )
@ -153,7 +153,7 @@ class StealEmoji(Cog):
msg = await self.bot.wait_for("message", check=check) msg = await self.bot.wait_for("message", check=check)
if msg.content.upper() in ["N", "NO"]: if msg.content.upper() in ["N", "NO"]:
await ctx.send("Cancelled") await ctx.maybe_send_embed("Cancelled")
return return
async with self.config.guildbanks() as guildbanks: async with self.config.guildbanks() as guildbanks:
@ -163,9 +163,9 @@ class StealEmoji(Cog):
guildbanks.append(ctx.guild.id) guildbanks.append(ctx.guild.id)
if already_a_guildbank: if already_a_guildbank:
await ctx.send("This server has been removed from being an emoji bank") await ctx.maybe_send_embed("This server has been removed from being an emoji bank")
else: else:
await ctx.send("This server has been added to be an emoji bank") await ctx.maybe_send_embed("This server has been added to be an emoji bank")
@commands.Cog.listener() @commands.Cog.listener()
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):

@ -97,7 +97,7 @@ class Game:
await self.get_roles(ctx) await self.get_roles(ctx)
if len(self.players) != len(self.roles): if len(self.players) != len(self.roles):
await ctx.send("Player count does not match role count, cannot start\n" await ctx.maybe_send_embed("Player count does not match role count, cannot start\n"
"Currently **{} / {}**\n" "Currently **{} / {}**\n"
"Use `{}ww code` to pick a new game" "Use `{}ww code` to pick a new game"
"".format(len(self.players), len(self.roles), ctx.prefix)) "".format(len(self.players), len(self.roles), ctx.prefix))
@ -112,7 +112,7 @@ class Game:
reason="(BOT) Werewolf game role") reason="(BOT) Werewolf game role")
self.to_delete.add(self.game_role) self.to_delete.add(self.game_role)
except (discord.Forbidden, discord.HTTPException): except (discord.Forbidden, discord.HTTPException):
await ctx.send("Game role not configured and unable to generate one, cannot start") await ctx.maybe_send_embed("Game role not configured and unable to generate one, cannot start")
self.roles = [] self.roles = []
return False return False
try: try:

Loading…
Cancel
Save