Commit b0f8fc04 authored by IS1_4M's avatar IS1_4M
Browse files

Added an abstract channel class

parent 24d89e16
......@@ -6,17 +6,31 @@ Created on Sat Sep 5 14:08:39 2020
"""
import discord
from AbstractChannel import AbstractChanSuite, AbstractChannel
def get_member_by_discord_name(guild, discord_name):
for member in guild.members:
if member.name + "#" + member.discriminator == discord_name:
return member
return False
class Club: # Creates a club category channel with CLUB MEMBER role read and write permissions for club members and CLI access for club convenors
Convenor_abstract_permissions = None
class Club(AbstractChannel): # Creates a club category channel with CLUB MEMBER role read and write permissions for club members and CLI access for club convenors
Convenor_cli_permissions = {'read_messages':True,
'send_message':True}
Member_permissions = {'read_messages':True,
'send_messages':True,
'connect':True,
'speak':True}
default_guild_role_perms = {'read_messages':False,
'send_messages':False,
'connect':False,
'speak': False}
convenor_color = discord.Colour.blue()
member_color = discord.Color.greyple()
Member_abstract_permissions = None
channel_type = 'c'
convener_role_name = 'Convener'
member_role_name = 'Member'
def __init__(self, guild, convener, clubName):
# Make a cli where commands from club conveners here can shape club below.
# Have list of all voice and text channels owned by the club.
......@@ -26,109 +40,43 @@ class Club: # Creates a club category channel with CLUB MEMBER role read and wri
#Auto give at least one person convener access to the club.
# Needs functionality to give other ECStudents convener roles.
self._guild = guild
self._convener = convener
self._clubName = 'c-' + clubName
AbstractChannel.__init__(self, guild, convener, clubName, Club.channel_type,
Club.convener_role_name,
Club.member_role_name,
Club.convenor_color,
Club.member_color,
Club.default_guild_role_perms,
Club.Member_permissions,
Club.Convenor_cli_permissions)
async def _init(self):
'''
CREATE & ASSIGN ROLES. (Expandable to include mods, operators, etc.)
'''
# Create convenor role
self._convener_role = await self._guild.create_role(name=self._clubName + " Convener", colour=Club.convenor_color)
# assign convener role
await self._convener.add_roles(self._convener_role)
# Create member role
self._member_role = await self._guild.create_role(name=self._clubName + " Member")
'''
CREATE HOLDER FOR CLUB ASSOCIATED STUDENT ROLES
'''
self._club_roles = [self._convener_role, self._member_role]
'''
CREATE CATEGORY CHANNEL W/ CLUB ASSOCIATED STUDENT ROLES PARTICIPATION PRIVILEDGES
'''
# Create channel
self._category = await self._guild.create_category(name=self._clubName)
for role in self._guild.roles:
await self._category.set_permissions(role, read_messages=False, send_messages=False)
for role in self._club_roles:
await self._category.set_permissions(role, read_messages=True, send_messages=True, connect=True, speak=True)
'''
CREATE CATEGORY DEFAULT TEXT CHANNELS
'''
# Create CLI text channel
self._cli = await self._category.create_text_channel(self._clubName + "-convenor-command-line")
# And make it private to all but conveners
for role in self._guild.roles:
await self._cli.set_permissions(role, read_messages=False, send_messages=False)
await self._cli.edit(topic = 'Only Conveners can use this channel')
await self._cli.set_permissions(self._convener_role, read_messages=True, send_messages=True)
await self._cli.send(ClubSuite.get_help_message(self._cli))
# Only Conveners of this club can post in this channel
# textchannel.set_permissions(rolename, read_messages=True, write_messages=True)
# self._cli_channel_id = None # Cli channel for the club
# Conveners and members of this club can post in this channel. (Use textchannel.set_permissions)
def __repr__(self):
return self._cli_channel_id
class ClubSuite:
await self._guild.create_role(name=self._channelName + " Member")
await AbstractChannel._init(self, [self._channelName + " Member"],
suite=ClubSuite)
class ClubSuite(AbstractChanSuite):
def get_all_clubs(guild): # returns list of club categories
roleNames= []
for role in guild.roles:
roleNames.append(role.name)
return filter(lambda x: x.name + ' Convener' in roleNames, guild.channels)
return AbstractChanSuite.get_all_chans(guild, Club.channel_type)
'''
Resolve club category from club category name
'''
def get_club(clubs, name):
for club in clubs:
if club.name.lower() == name.lower():
return club
return None
return AbstractChanSuite.get_chan(clubs, name)
def get_club_roles(club):
roles = []
for role in club.guild.roles:
if role.name.startswith(club.name):
roles.append(role)
return roles
'''
Resolve club role from club and full role name
'''
def get_role(club, roleName):
for role in club.guild.roles:
print(role.name, roleName)
if role.name == roleName:
return role
return None
return AbstractChanSuite.get_chan_roles(club)
'''
Returns club category that matches proposed cli if there is one.
'''
def is_cli(clubs, channel):
for club in clubs:
if club.name.lower() + "-convenor-command-line" == channel.name:
return club
return False
def is_cli(clubs, check_channel):
return AbstractChanSuite.is_cli(clubs, check_channel, Club.convener_role_name)
'''
Returns the cli for the given club category channel
'''
def get_cli(category):
for channel in category.channels:
if category.name.lower() + '-convenor-command-line' == channel.name.lower():
return channel
return False
return AbstractChanSuite.get_cli(category, Club.convener_role_name)
'''
Create a new role for the club.
......@@ -136,28 +84,28 @@ class ClubSuite:
role_name: a string of the new role name. Ex: Organizer
permissions: Permissions item to give the role
'''
async def add_role(club, role_name, permissions):
await club.guild.create_role(club.name + ' ' + role_name, permissions) # Unstable.
async def add_role_to_user(club, member, role):
await member.add_roles(ClubSuite.get_role(club, role))
#await club.guild.create_role(club.name + ' ' + role_name, permissions) # Unstable.
# Add new convener to the club
async def add_convener(club, member, convener_role_name=None):
if convener_role_name == None:
convener_role_name = club.name + ' Convener'
await member.add_roles(ClubSuite.get_role(club, convener_role_name))
async def add_convener(club, member):
convener_role_name = Club.convener_role_name
print(convener_role_name)
await AbstractChanSuite.add_CLIUser(club, member, convener_role_name)
# Add new members to the club
async def add_member(club, member, member_role_name=None):
if member_role_name == None:
member_role_name = club.name + ' Member'
async def add_member(club, member):
member_role_name = club.name + ' ' + Club.member_role_name
await member.add_roles(ClubSuite.get_role(club, member_role_name))
async def kick_member(club, member, member_role_name=None):
if member_role_name == None:
member_role_name = club.name + ' Member'
await member.remove_roles(ClubSuite.get_role(club, member_role_name))
async def remove_as_convenver(club, member):
await member.remove_roles(ClubSuite.get_role(club, club.name + ' ' + Club.convener_role_name))
async def ban_member(self, member):
# permaban member from the club
# do not allow join if on a list, i guess
......@@ -167,70 +115,6 @@ class ClubSuite:
# remove from the list, i guess
pass
'''
add text channel to resolved club category channel
'''
async def add_text_channel(club, channelName):
# add a text channel to this category.
await club.create_text_channel(channelName)
async def remove_text_channel(club, channel_name):
channel_name = channel_name.lower()
#remove text channel from category
for channel in club.text_channels:
if channel.name.lower() == channel_name:
await channel.delete()
return True
return False
async def get_text_channel(club, channel_name):
channel_name = channel_name.lower()
#remove text channel from category
for channel in club.text_channels:
if channel.name.lower() == channel_name:
return channel
return False
'''
add text channel to resolved club category channel
'''
async def add_voice_channel(club, channelName):
#add voice channel to category
await club.create_voice_channel(channelName)
async def remove_voice_channel(club, channel_name):
#remove voice channel from this category
channel_name = channel_name.lower()
for channel in club.voice_channels:
if channel.name == channel_name:
await channel.delete()
return True
return False
async def delete_category(club): # Provide your category
# Ask "are you sure" in the discord cli. if yes, delete the category.
# if no, don't. Return true or false if category was successfully/unsuccessfully deleted, respectively.
# Remove the clubnameX roles from the discord.
'''
TAKE LOG OF ALL PRIOR ACTIVITY FROM ALL EXISTING TEXT CHANNELS
'''
#TODO
'''
DELETE ASSOCIATED CHANNELS & CATEGORIES
'''
for channel in club.text_channels + club.voice_channels:
await channel.delete()
'''
DELETE ASSOCIATED CLUB ROLES
'''
for role in ClubSuite.get_club_roles(club):
await role.delete()
await club.delete()
def get_club_commands():
return ['!describe description - Registers your club description. You can put spaces in description.',
'!pin channel-to-pin-to-in-club message-to-pin - Pins message-to-pin to channel-to-pin-to-in-club',
......@@ -297,7 +181,10 @@ class ClubSuite:
await ClubSuite.kick_member(maybe_club, member); return True
elif content.startswith('!convenerhelp'):
await message.channel.send(ClubSuite.get_help_message(message.channel)); return True
elif content.startswith('!describe'):
elif content.startswith('!describe '):
for pin in message.channel.pins:
if pin.content.startswith("DESCRIPTION SET TO:"):
await pin.unpin()
await (await message.channel.send('DESCRIPTION SET TO: ' + content[len('!describe '):])).pin()
return True
elif content.startswith('!pin'):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment