Skip to content

Commit

Permalink
[Say] Version 1.5 (allow mentions)
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit cd7e7e4a0ea7c8a447dc9e11bf2078599c082792
Author: retke <laggron42@gmail.com>
Date:   Thu Dec 3 10:41:45 2020 +0100

    Allow administrators to use commands

commit 5c09f57a3661bfa14705e9b40914b96325874f2a
Author: retke <laggron42@gmail.com>
Date:   Thu Dec 3 10:39:47 2020 +0100

    Add saym command for mentions
  • Loading branch information
laggron42 committed Dec 3, 2020
1 parent a6f7d9b commit 6aadfa4
Showing 1 changed file with 68 additions and 9 deletions.
77 changes: 68 additions & 9 deletions say/say.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def __init__(self, bot):
__version__ = "1.4.14"

async def say(
self, ctx: commands.Context, channel: Optional[discord.TextChannel], text: str, files: list
self,
ctx: commands.Context,
channel: Optional[discord.TextChannel],
text: str,
files: list,
mentions: discord.AllowedMentions = None,
):
if not channel:
channel = ctx.channel
Expand All @@ -59,10 +64,10 @@ async def say(

# sending the message
try:
await channel.send(text, files=files)
await channel.send(text, files=files, allowed_mentions=mentions)
except discord.errors.HTTPException as e:
author = ctx.author
if not ctx.guild.me.permissions_in(channel).send_messages:
author = ctx.author
try:
await ctx.send(
_("I am not allowed to send messages in ") + channel.mention,
Expand Down Expand Up @@ -91,8 +96,10 @@ async def say(
)

@commands.command(name="say")
@checks.guildowner()
async def _say(self, ctx, channel: Optional[discord.TextChannel], *, text: str = ""):
@checks.admin_or_permissions(administrator=True)
async def _say(
self, ctx: commands.Context, channel: Optional[discord.TextChannel], *, text: str = ""
):
"""
Make the bot say what you want in the desired channel.
Expand All @@ -108,8 +115,10 @@ async def _say(self, ctx, channel: Optional[discord.TextChannel], *, text: str =
await self.say(ctx, channel, text, files)

@commands.command(name="sayd", aliases=["sd"])
@checks.guildowner()
async def _saydelete(self, ctx, channel: Optional[discord.TextChannel], *, text: str = ""):
@checks.admin_or_permissions(administrator=True)
async def _saydelete(
self, ctx: commands.Context, channel: Optional[discord.TextChannel], *, text: str = ""
):
"""
Same as say command, except it deletes your message.
Expand All @@ -130,9 +139,59 @@ async def _saydelete(self, ctx, channel: Optional[discord.TextChannel], *, text:

await self.say(ctx, channel, text, files)

@commands.command(name="saym", aliases=["sm"])
@checks.admin_or_permissions(administrator=True)
async def _saymention(
self, ctx: commands.Context, channel: Optional[discord.TextChannel], *, text: str = ""
):
"""
Same as say command, except role and mass mentions are enabled.
"""
message = ctx.message
channel = channel or ctx.channel
guild = channel.guild
files = await Tunnel.files_from_attach(message)
role_mentions = message.role_mentions
if not role_mentions and not message.mention_everyone:
# no mentions, nothing to check
return await self.say(ctx, channel, text, files)
no_mention = [x for x in role_mentions if x.mentionable is False]
if guild.me.guild_permissions.administrator is False:
if no_mention:
await ctx.send(
_(
"I can't mention the following roles: {roles}\nTurn on "
"mentions or make me an admin on the server.\n"
).format(roles=", ".join([x.name for x in no_mention]))
)
return
if (
message.mention_everyone
and channel.permissions_for(guild.me).mention_everyone is False
):
await ctx.send(_("I don't have the permission to mention everyone."))
return
if (
message.mention_everyone
and channel.permissions_for(ctx.author).mention_everyone is False
):
await ctx.send(_("You don't have the permission yourself to do mass mentions."))
return
if ctx.author.guild_permissions.administrator is False and no_mention:
await ctx.send(
_(
"You're not allowed to mention the following roles: {roles}\nTurn on "
"mentions for that role or be an admin in the server.\n"
).format(roles=", ".join([x.name for x in no_mention]))
)
return
await self.say(
ctx, channel, text, files, mentions=discord.AllowedMentions(everyone=True, roles=True)
)

@commands.command(name="interact")
@checks.guildowner()
async def _interact(self, ctx, channel: discord.TextChannel = None):
@checks.admin_or_permissions(administrator=True)
async def _interact(self, ctx: commands.Context, channel: discord.TextChannel = None):
"""Start receiving and sending messages as the bot through DM"""

u = ctx.author
Expand Down

0 comments on commit 6aadfa4

Please sign in to comment.