Skip to content
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

amalgamate !joinchannel messages. #54

Merged
merged 4 commits into from
Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions uqcsbot/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
JOINED_PERMISSIONS = discord.Permissions(read_messages=True)
SERVER_ID = 813324385179271168
# Testing Server
#SERVER_ID = 836589565237264415

# SERVER_ID = 836589565237264415
class Channels(commands.Cog):

def __init__(self, bot: UQCSBot):
Expand Down Expand Up @@ -48,30 +47,47 @@ async def on_ready(self):
@commands.command()
async def joinchannel(self, ctx: commands.Context, *channels: str):
""" Joins the channel (or channels) that you specify. """
joined = []
already = []
failed = []
for channel in channels:
channel_query = self._channel_query(channel)

if channel_query == None:
await ctx.send(f"Unable to join {channel}.")
failed.append(channel)
continue

channel = self.bot.get_channel(channel_query.id)
guild = self.bot.get_guild(SERVER_ID)
member = guild.get_member(ctx.author.id)

if channel == None:
await ctx.send(f"Unable to join {channel}.")
failed.append(channel)
continue

# Don't let a user join the channel again if they are already in it.
if channel.permissions_for(member).is_superset(JOINED_PERMISSIONS):
await ctx.send(f"You're already a member of {channel}.")
already.append(channel)
continue

await channel.set_permissions(member, read_messages=True, reason="UQCSbot added.")
join_message = await channel.send(f"{member.display_name} joined {channel.mention}")
await join_message.add_reaction("👋")
await ctx.send(f"You've joined {channel.mention}.")
joined.append(channel)

commas = lambda chans: ', '.join(map(str, chans))
message = []
if joined:
message.append(f"You've joined {commas(joined)}.")
if already:
message.append(f"You're already a member of {commas(already)}.")
if failed:
message.append(f"Unable to join {commas(failed)}.")

if message:
await ctx.send('\n'.join(message))
else:
await ctx.send("... but nothing happened!")

@commands.command(hidden=True)
async def joinchannels(self, ctx: commands.Context, *channels: str):
Expand Down