Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #56 from parafoxia/develop
Browse files Browse the repository at this point in the history
Merge to release 1.1.2
  • Loading branch information
parafoxia authored Sep 12, 2020
2 parents 649bd45 + 9a6b3a3 commit 92e3c97
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Solaris-Bot"
version = "1.1.1"
version = "1.1.2"
description = "A Discord bot designed to make your server a safer and better place."

license = "GPLv3"
Expand Down
35 changes: 18 additions & 17 deletions solaris/bot/cogs/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ async def on_ready(self):
async def on_member_join(self, member):
if self.bot.ready.gateway:
okay = Okay(self.bot, member.guild)
active, rc_id, gm_id, br_id, wc_id, timeout, wbt = (
active, br_id, wc_id, timeout, wbt = (
await self.bot.db.record(
"SELECT Active, RulesChannelID, GateMessageID, BlockingRoleID, WelcomeChannelID, Timeout, WelcomeBotText FROM gateway WHERE GuildID = ?",
"SELECT Active, BlockingRoleID, WelcomeChannelID, Timeout, WelcomeBotText FROM gateway WHERE GuildID = ?",
member.guild.id,
)
or [None] * 7
Expand All @@ -279,7 +279,7 @@ async def on_member_join(self, member):
if wc := await okay.welcome_channel(wc_id):
await wc.send(
self.format_custom_message(wbt, member)
or f'The bot "{member.mention}" was added to the server.'
or f"‎The bot {member.mention} was added to the server."
)
else:
if br := await okay.blocking_role(br_id):
Expand All @@ -291,21 +291,13 @@ async def on_member_join(self, member):
chron.to_iso(member.joined_at + dt.timedelta(seconds=timeout or 300)),
)

if (gm := await okay.gate_message(rc_id, gm_id)) :
for emoji in self.bot.emoji.get_many("confirm", "cancel"):
try:
await gm.remove_reaction(emoji, member)
except discord.NotFound:
# In the rare instance the module trips while attempting to remove a reaction.
pass

@commands.Cog.listener()
async def on_member_remove(self, member):
if self.bot.ready.gateway:
okay = Okay(self.bot, member.guild)
active, gc_id, gt, gbt = (
active, rc_id, gm_id, gc_id, gt, gbt = (
await self.bot.db.record(
"SELECT Active, GoodbyeChannelID, GoodbyeText, GoodbyeBotText FROM gateway WHERE GuildID = ?",
"SELECT Active, RulesChannelID, GateMessageID, GoodbyeChannelID, GoodbyeText, GoodbyeBotText FROM gateway WHERE GuildID = ?",
member.guild.id,
)
or [None] * 4
Expand All @@ -316,7 +308,7 @@ async def on_member_remove(self, member):
if gc := okay.goodbye_channel(gc_id):
await gc.send(
self.format_custom_message(gbt, member)
or f'The bot "{member.display_name}" was removed from the server.'
or f'The bot "{member.display_name}" was removed from the server.'
)
else:
if await self.bot.db.field(
Expand All @@ -328,13 +320,21 @@ async def on_member_remove(self, member):
elif gc := await okay.goodbye_channel(gc_id):
await gc.send(
self.format_custom_message(gt, member)
or f"{member.display_name} is no longer in the server."
or f"{member.display_name} is no longer in the server."
)

await self.bot.db.execute(
"DELETE FROM accepted WHERE GuildID = ? AND UserID = ?", member.guild.id, member.id
)

if (gm := await okay.gate_message(rc_id, gm_id)) :
for emoji in self.bot.emoji.get_many("confirm", "cancel"):
try:
await gm.remove_reaction(emoji, member)
except discord.NotFound:
# In the rare instance the module trips while attempting to remove a reaction.
pass

@commands.Cog.listener()
async def on_member_update(self, before, after):
if self.bot.ready.gateway and len(after.roles) > len(before.roles):
Expand Down Expand Up @@ -378,7 +378,8 @@ def format_custom_message(text, member):
bot_count = len([m for m in member.guild.members if m.bot])
human_count = member.guild.member_count - bot_count

return string.safe_format(
# Contains U+200E character.
return "‎" + string.safe_format(
text,
membername=member.name,
username=member.name,
Expand Down Expand Up @@ -409,7 +410,7 @@ async def allow_on_accept(self, member, okay, br_id, mr_ids, wc_id, wt):
if wc := await okay.welcome_channel(wc_id):
await wc.send(
self.format_custom_message(wt, member)
or f"{member.mention} joined the server and accepted the rules. Welcome!"
or f"{member.mention} joined the server and accepted the rules. Welcome!"
)

await self.bot.db.execute(
Expand Down
1 change: 1 addition & 0 deletions solaris/bot/cogs/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ async def messageinfo_command(self, ctx, target: t.Union[discord.Message, str]):
)
async def emojiinfo_command(self, ctx, target: t.Union[discord.Emoji, str]):
if isinstance(target, discord.Emoji):
target = await ctx.guild.fetch_emoji(target.id)
await ctx.send(
embed=self.bot.embed.build(
ctx=ctx,
Expand Down
8 changes: 5 additions & 3 deletions solaris/bot/cogs/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def kick_command(
async def ban_command(
self,
ctx,
targets: commands.Greedy[discord.Member],
targets: commands.Greedy[t.Union[discord.Member, converters.User]],
delete_message_days: t.Optional[int] = 1,
*,
reason: t.Optional[str] = "No reason provided.",
Expand All @@ -93,8 +93,10 @@ async def ban_command(
async with ctx.typing():
for target in targets:
try:
await target.ban(
delete_message_days=delete_message_days, reason=f"{reason} - Actioned by {ctx.author.name}"
await ctx.guild.ban(
target,
delete_message_days=delete_message_days,
reason=f"{reason} - Actioned by {ctx.author.name}",
)
count += 1
except discord.Forbidden:
Expand Down
14 changes: 7 additions & 7 deletions solaris/utils/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ async def convert(self, ctx, arg):
class BannedUser(commands.Converter):
async def convert(self, ctx, arg):
if ctx.guild.me.guild_permissions.ban_members:
if arg.isdigit():
try:
return await ctx.guild.fetch_ban(discord.Object(id=int(arg)))
except discord.NotFound:
raise commands.BadArgument

banned = [e.user for e in await ctx.guild.bans()]
if banned:
if re.match(r"[0-9]{17,22}", arg) is not None:
if (user := discord.utils.get(banned, id=int(arg))) is None:
raise commands.BadArgument
return user
elif (match := re.match(r"([\s\S]{2,32})#([0-9]{4})", arg)) is not None:
if (user := discord.utils.get(banned, name=match.group(1), discriminator=match.group(2))) is None:
raise commands.BadArgument
if (user := discord.utils.find(lambda u: str(u) == arg, banned)) is not None:
return user
else:
raise commands.BadArgument

0 comments on commit 92e3c97

Please sign in to comment.