forked from viveksantayana/geas-bot
142 lines
8.5 KiB
Python
142 lines
8.5 KiB
Python
import discord
|
||
from discord.ext import commands, tasks
|
||
from datetime import datetime
|
||
|
||
def membershipSignupChannels(client):
|
||
l = []
|
||
for guild in client.guilds:
|
||
channel = discord.utils.find(lambda c: c.name == '📋-membership-signups', guild.channels)
|
||
l.append(channel)
|
||
return l
|
||
|
||
def committeeRoles(client):
|
||
l = []
|
||
for guild in client.guilds:
|
||
role = discord.utils.find(lambda r: r.name == 'Committee', guild.roles)
|
||
l.append(role)
|
||
return l
|
||
|
||
def checkCommitteeRoles(author,committee):
|
||
if set(author.roles) & set(committee):
|
||
return True
|
||
|
||
class MembershipVerification(commands.Cog, name='Membership Verification Commands'):
|
||
def __init__(self,client):
|
||
self.client = client
|
||
|
||
# Message in Membership Signup event listener.
|
||
@commands.Cog.listener()
|
||
async def on_message(self,message):
|
||
if message.channel in membershipSignupChannels(self.client) and message.author.id != self.client.user.id:
|
||
if message.attachments == []:
|
||
await message.author.send(f'**Error**: The message you posted in the {message.channel.name} channel of {message.guild.name} was invalid. Your post must contain a screensot of your proof of purchase for membership from EUSA.')
|
||
await message.delete()
|
||
return
|
||
await message.add_reaction('1️⃣')
|
||
await message.add_reaction('2️⃣')
|
||
await message.add_reaction('📅')
|
||
await message.add_reaction('📚')
|
||
await message.add_reaction('⚠️')
|
||
await message.add_reaction('🚫')
|
||
|
||
@commands.Cog.listener()
|
||
async def on_raw_reaction_add(self,payload):
|
||
if payload.user_id != self.client.user.id and self.client.get_channel(payload.channel_id) in membershipSignupChannels(self.client):
|
||
guild = await self.client.fetch_guild(payload.guild_id)
|
||
member = await guild.fetch_member(payload.user_id)
|
||
channel = await self.client.fetch_channel(payload.channel_id)
|
||
message = await channel.fetch_message(payload.message_id)
|
||
studentsRole = discord.utils.find(lambda g: g.name == 'Students', guild.roles)
|
||
semesterOneRole = discord.utils.find(lambda g: g.name == 'Members: Semester 1', guild.roles)
|
||
semesterTwoRole = discord.utils.find(lambda g: g.name == 'Members: Semester 2', guild.roles)
|
||
fullYearRole = discord.utils.find(lambda g: g.name == 'Members: Full Year', guild.roles)
|
||
channels = await guild.fetch_channels()
|
||
committeeChannel = discord.utils.find(lambda t: t.name == '🗞-moderator-logs', channels)
|
||
committeeRole = discord.utils.find(lambda c: c.name == 'Committee', guild.roles)
|
||
if not checkCommitteeRoles(member, committeeRoles(self.client)):
|
||
await member.send(f'**Error**: Only Committee members are authorised to react to posts on the {channel.name} channel for {guild.name}.')
|
||
await message.remove_reaction(payload.emoji.name, member)
|
||
return
|
||
if payload.emoji.name == '1️⃣':
|
||
await message.author.add_roles(semesterOneRole)
|
||
await message.add_reaction('✅')
|
||
await message.author.send(f'Your membership for {guild.name} has been verified and you have been assigned the role **Members: Semester 1**.')
|
||
return
|
||
if payload.emoji.name == '2️⃣':
|
||
await message.author.add_roles(semesterTwoRole)
|
||
await message.add_reaction('✅')
|
||
await message.author.send(f'Your membership for {guild.name} has been verified and you have been assigned the role **Members: Semester 2**.')
|
||
return
|
||
if payload.emoji.name == '📅':
|
||
await message.author.add_roles(fullYearRole)
|
||
await message.add_reaction('✅')
|
||
await message.author.send(f'Your membership for {guild.name} has been verified and you have been assigned the role **Members: Full Year**.')
|
||
return
|
||
if payload.emoji.name == '📚':
|
||
await message.author.add_roles(studentsRole)
|
||
await message.author.send(f'You have additionally been assigned the role **Students**.')
|
||
return
|
||
if payload.emoji.name == '⚠️':
|
||
embed = discord.Embed(
|
||
title = message.author.name,
|
||
description = f'[Jump to Message]({message.jump_url})',
|
||
colour = discord.Colour.orange(),
|
||
)
|
||
await message.author.send(f'Your membership for {guild.name} needs to be reviewed by a Committee member.')
|
||
await committeeChannel.send(f'Hey {committeeRole.mention}, there is a problem verifying the membership of {message.author.mention}.\nCould someone verify this person\'s membership manually via the EUSA portal and return to the message?', embed=embed)
|
||
return
|
||
if payload.emoji.name == '🚫':
|
||
embed = discord.Embed(
|
||
title = message.author.name,
|
||
description = f'[Jump to Message]({message.jump_url})',
|
||
colour = discord.Colour.red(),
|
||
)
|
||
await message.author.send(f'Your membership for {guild.name} could not be verified. Please make sure that your name and the kind of membership you have bought are visible in the screenshot you upload. Please contact a Committee member if you have any difficulties.')
|
||
await committeeChannel.send(f'Hey {committeeRole.mention}, verifying the membership of {message.author.mention} failed.', embed=embed)
|
||
return
|
||
|
||
@commands.Cog.listener()
|
||
async def on_raw_reaction_remove(self,payload):
|
||
if payload.user_id != self.client.user.id and self.client.get_channel(payload.channel_id) in membershipSignupChannels(self.client):
|
||
guild = await self.client.fetch_guild(payload.guild_id)
|
||
member = await guild.fetch_member(payload.user_id)
|
||
channel = await self.client.fetch_channel(payload.channel_id)
|
||
message = await channel.fetch_message(payload.message_id)
|
||
studentsRole = discord.utils.find(lambda g: g.name == 'Students', guild.roles)
|
||
semesterOneRole = discord.utils.find(lambda g: g.name == 'Members: Semester 1', guild.roles)
|
||
semesterTwoRole = discord.utils.find(lambda g: g.name == 'Members: Semester 2', guild.roles)
|
||
fullYearRole = discord.utils.find(lambda g: g.name == 'Members: Full Year', guild.roles)
|
||
channels = await guild.fetch_channels()
|
||
committeeChannel = discord.utils.find(lambda t: t.name == '🗞-moderator-logs', channels)
|
||
committeeRole = discord.utils.find(lambda c: c.name == 'Committee', guild.roles)
|
||
if not checkCommitteeRoles(member, committeeRoles(self.client)):
|
||
await message.remove_reaction(payload.emoji.name, member)
|
||
return
|
||
if payload.emoji.name == '1️⃣':
|
||
await message.author.remove_roles(semesterOneRole)
|
||
await message.remove_reaction('✅',self.client.user)
|
||
await message.author.send(f'Your role **Members: Semester 1** for {guild.name} has been removed.')
|
||
return
|
||
if payload.emoji.name == '2️⃣':
|
||
await message.author.remove_roles(semesterTwoRole)
|
||
await message.remove_reaction('✅',self.client.user)
|
||
await message.author.send(f'Your role **Members: Semester 2** for {guild.name} has been removed.')
|
||
return
|
||
if payload.emoji.name == '📅':
|
||
await message.author.remove_roles(fullYearRole)
|
||
await message.remove_reaction('✅',self.client.user)
|
||
await message.author.send(f'Your role **Members: Full Year** for {guild.name} has been removed.')
|
||
return
|
||
if payload.emoji.name == '📚':
|
||
await message.author.remove_roles(studentsRole)
|
||
await message.author.send(f'Your role **Students** for {guild.name} has been removed.')
|
||
return
|
||
if payload.emoji.name == '⚠️':
|
||
await message.author.send(f'Your membership for {guild.name} is being reviewed by a Committee member.')
|
||
return
|
||
if payload.emoji.name == '🚫':
|
||
await message.author.send(f'Your membership for {guild.name} is being reviewed by a Committee member.')
|
||
return
|
||
|
||
def setup(client):
|
||
client.add_cog(MembershipVerification(client)) |