Commit 6db616fc authored by IS1_4M's avatar IS1_4M
Browse files

reorganized backend for later scalability

parent 28f1893c
......@@ -90,8 +90,9 @@ class AbstractChanSuite:
Resolve club category from club category name
'''
def get_chan(chans, name):
formatted = AbstractChanSuite.format_uinp(name)
for chan in chans:
if chan.name.lower() == name.lower():
if chan.name.lower() == formatted:
return chan
return None
......@@ -230,5 +231,12 @@ class AbstractChanSuite:
def get_help_message(channel):
return "Not Implemented"
async def process_cli_commands(message):
raise NotImplementedError()
async def process_user_commands(message):
raise NotImplementedError()
async def process_commands(message):
raise NotImplementedError()
\ No newline at end of file
return await AbstractChanSuite.process_cli_commands(message) or await AbstractChanSuite.process_user_commands(message)
\ No newline at end of file
......@@ -153,7 +153,7 @@ async def on_message(message):
Check if the channel mentioned is a cli for a club. if so, perform club commands.
'''
# try catch around this boy
if await ClubSuite.processes_inc_command(message):
if await ClubSuite.process_commands(message):
await message.channel.send('Succeeded...', delete_after=3)
return
......
......@@ -132,49 +132,35 @@ class ClubSuite(AbstractChanSuite):
send_text += command + '\n\t'
return send_text
async def processes_inc_command(message):
print('attempting to proccess as a club command')
async def process_cli_commands(message):
content = message.content.lower()
try:
maybe_club = ClubSuite.is_cli(ClubSuite.get_all_clubs(message.channel.guild), message.channel) #''' This will break the program later. message.channel can be a DM channel. find a way to make it so that that wont break the channel'''
if maybe_club == False:
if content.startswith('!describeclub'):
cli = ClubSuite.get_cli(ClubSuite.get_club(ClubSuite.get_all_clubs(message.channel.guild), 'C-' + content[len('!describeclub '):].replace(' ', '-')))
if cli != False:
for pin in await cli.pins():
if pin.content.startswith('DESCRIPTION SET TO: '):
await message.channel.send(content[len('!describeclub '):] + '\'s description is: ' + pin.content[len('DESCRIPTION SET TO: '):])
return True
await message.channel.send('Aww... ' + content[len('!describeclub '):] + ' hasn\'t set a description yet. Check back later!')
return True
print("returning false from maybe clubbing comand lining")
return False
except:
print('could not find guild')
return False
print(content, content.startswith('!addvoicechannel'))
message_parts = content.split(' ')
club = AbstractChanSuite.is_cli(AbstractChanSuite.get_all_chans(message.guild, Club.channel_type), message.channel, Club.convener_role_name)
if not club:
return False # Did not process commands
if content.startswith('!addtextchannel '): # Add club text channel
await ClubSuite.add_text_channel(maybe_club, content[len('!addtextchannel '):]); return True
await ClubSuite.add_text_channel(club, content[len('!addtextchannel '):]); return True
elif content.startswith('!removetextchannel'): # remove club text channel
await ClubSuite.remove_text_channel(maybe_club, content[len('!removetextchannel '):].replace(' ', '-')); return True
await ClubSuite.remove_text_channel(club, content[len('!removetextchannel '):].replace(' ', '-')); return True
elif content.startswith('!addvoicechannel'): #add club voice channel
print('arrived at clubsuite addvoicechannel: ' + message.content)
await ClubSuite.add_voice_channel(maybe_club, content[len('!addvoicechannel '):]);
await ClubSuite.add_voice_channel(club, content[len('!addvoicechannel '):]);
print('completed addvoicechannel')
return True
elif content.startswith('!removevoicechannel'): # remove club voice channel
await ClubSuite.remove_voice_channel(maybe_club, content[len('!removevoicechannel '):].replace(' ', '-')); return True
await ClubSuite.remove_voice_channel(club, content[len('!removevoicechannel '):].replace(' ', '-')); return True
elif content.startswith('!closeclub'):
await ClubSuite.delete_category(maybe_club); return True
await ClubSuite.delete_category(club); return True
elif content.startswith('!addmember'):
member = get_member_by_discord_name(message.guild, content[len('!addmember '):])
await ClubSuite.add_member(maybe_club, member); return True
await ClubSuite.add_member(club, member); return True
elif content.startswith('!addconvener'):
member = get_member_by_discord_name(message.guild, message.content[len('!addconvener '):])#'''ADDCONVENER NEEDS SOME WORK'''
await ClubSuite.add_convener(maybe_club, member); return True
await ClubSuite.add_convener(club, member); return True
elif content.startswith('!kick'):
member = get_member_by_discord_name(message.guild, content[len('!kick '):])
await ClubSuite.kick_member(maybe_club, member); return True
await ClubSuite.kick_member(club, member); return True
elif content.startswith('!convenerhelp'):
await message.channel.send(ClubSuite.get_help_message(message.channel)); return True
elif content.startswith('!describe '):
......@@ -187,14 +173,14 @@ class ClubSuite(AbstractChanSuite):
terms = content.split(' ')
if len(terms) < 3:
await message.channel.send('!pin requires 3 things! Here\'s an example: !pin MyClubTextChannel what I want to pin and you can include spaces here', delete_after = 10)
channel = await ClubSuite.get_text_channel(maybe_club, terms[1])
channel = await ClubSuite.get_text_channel(club, terms[1])
if channel != False:
await (await channel.send(' '.join(terms[2:]))).pin()
elif content.startswith('!unpin'):
terms = content.split(' ')
if len(terms) < 3:
await message.channel.send('!pin requires 3 things! Here\'s an example: !pin MyClubTextChannel what I want to pin and you can include spaces here', delete_after = 10)
channel = await ClubSuite.get_text_channel(maybe_club, terms[1])
channel = await ClubSuite.get_text_channel(club, terms[1])
content = ' '.join(terms[2:])
if channel != False:
for pin in await channel.pins():
......@@ -205,6 +191,24 @@ class ClubSuite(AbstractChanSuite):
elif content.startswith('!requestbot'):
await message.channel.send('We will get back to you soon with questions and information about your bot!')
return True#unimplemented. To implement Soon
print('returning false as a club channel')
return False
async def process_user_commands(message):
content = message.content.lower()
message_parts = content.split(' ')
if content.startswith('!describeclub'):
cli = ClubSuite.get_cli(ClubSuite.get_club(ClubSuite.get_all_clubs(message.channel.guild), Club.channel_type + '-' + content[len('!describeclub '):].replace(' ', '-')))
if cli != False:
for pin in await cli.pins():
if pin.content.startswith('DESCRIPTION SET TO: '):
await message.channel.send(content[len('!describeclub '):] + '\'s description is: ' + pin.content[len('DESCRIPTION SET TO: '):])
return True
await message.channel.send('Aww... ' + content[len('!describeclub '):] + ' hasn\'t set a description yet. Check back later!')
return True
elif 1==1:
pass
return False
async def process_commands(message):
return await ClubSuite.process_cli_commands(message) or await ClubSuite.process_user_commands(message)
\ No newline at end of file
......@@ -106,64 +106,47 @@ class PubChanSuite(AbstractChanSuite):
send_text += command + '\n\t'
return send_text
async def process_commands(message):
async def process_cli_commands(message):
return False
async def process_user_commands(message):
content = message.content.lower()
if len(content.split(' ')) < 3:
return False
if content.startswith('!addtextchannel'):
params = content[len('!addtextchannel '):].split(' ')
target = 'O-' + params[0].upper().replace(' ', '-')
channel = '-'.join(params[1:])
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
message_parts = content.split(' ')
if len(message_parts) >= 3:
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), PublicChan.channel_type + '-' + message_parts[1])
if pubchan:
start_role = await message.channel.guild.create_role(name=target + channel + ' Starter')
await message.author.add_roles(start_role)
await PubChanSuite.add_text_channel(pubchan, channel)
return True
else:
return False
# remove a text channel from a hangout space.
elif content.startswith('!removetextchannel'):
params = content[len('!removetextchannel '):].split(' ')
target = 'O-' +params[0].upper()
channel = '-'.join(params[1:])
if target + channel + ' Starter' in [role.name for role in message.author.roles]:
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
for role in message.channel.guild.roles:
if role.name == target + channel + ' Starter':
await message.author.remove_roles(role)
await role.delete()
break
await PubChanSuite.remove_text_channel(pubchan, channel)
return True
else:
await message.channel.send('You either dont have permission to do that or you typod a name...', delete_after = 3)
return False
elif content.startswith('!addvoicechannel'):
params = content[len('!addvoicechannel '):].split(' ')
target = 'O-' +params[0].upper().replace(' ','-')
channel = '-'.join(params[1:])
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
if pubchan:
start_role = await message.channel.guild.create_role(name=target + channel + ' Starter')
await message.author.add_roles(start_role)
await PubChanSuite.add_voice_channel(pubchan, channel)
return True
else:
return False
elif content.startswith('!removevoicechannel'):
params = content[len('!removevoicechannel '):].split(' ')
target = 'O-' +params[0].upper()
channel = '-'.join(params[1:])
if target + channel + ' Starter' in [role.name for role in message.author.roles]:
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
for role in message.channel.guild.roles:
if role.name == target + channel + ' Starter':
await message.author.remove_roles(role)
await role.delete()
break
await PubChanSuite.remove_voice_channel(pubchan, channel.lower())
return True
else:
await message.channel.send('You either dont have permission to do that or you typod a name...', delete_after = 3)
return False
\ No newline at end of file
target = pubchan.name
channel = '-'.join(message_parts[2:])
if content.startswith('!addtextchannel'):
start_role = await message.channel.guild.create_role(name=target + ' ' + channel + ' Starter') # Someone has to streamline this. THis is shit.
await message.author.add_roles(start_role)
await PubChanSuite.add_text_channel(pubchan, channel)
return True
elif content.startswith('!removetextchannel'):
if target + ' ' + channel + ' Starter' in [role.name for role in message.author.roles]:
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
for role in message.channel.guild.roles:
if role.name == target + channel + ' Starter':
await message.author.remove_roles(role)
await role.delete()
break
await PubChanSuite.remove_text_channel(pubchan, channel)
return True
elif content.startswith('!addvoicechannel'):
start_role = await message.channel.guild.create_role(name=target + ' ' + channel + ' Starter') # Someone has to streamline this. THis is shit.
await message.author.add_roles(start_role)
await PubChanSuite.add_voice_channel(pubchan, channel)
return True
elif content.startswith('!removevoicechannel'):
if target + ' ' + channel + ' Starter' in [role.name for role in message.author.roles]:
pubchan = PubChanSuite.get_pubchan(PubChanSuite.get_all_pubchans(message.channel.guild), target)
for role in message.channel.guild.roles:
if role.name == target + channel + ' Starter':
await message.author.remove_roles(role)
await role.delete()
break
await PubChanSuite.remove_voice_channel(pubchan, channel)
return True
return False
async def process_commands(message):
return await PubChanSuite.process_cli_commands(message) or await PubChanSuite.process_user_commands(message)
\ No newline at end of file
......@@ -108,43 +108,42 @@ class RestrictChanSuite(AbstractChanSuite):
for command in commands:
send_text += command + '\n\t'
return send_text
async def process_commands(message):
async def process_cli_commands(message):
content = message.content.lower()
try:
maybe_restrict_chan = RestrictChanSuite.is_cli(RestrictChanSuite.get_all_restrictchans(message.channel.guild), message.channel) #''' This will break the program later. message.channel can be a DM channel. find a way to make it so that that wont break the channel'''
if content.startswith('!addtextchannel'):
await RestrictChanSuite.add_text_channel(maybe_restrict_chan, content[len('!addtextchannel '):])
elif content.startswith('!removetextchannel'):
await RestrictChanSuite.remove_text_channel(maybe_restrict_chan, content[len('!removetextchannel '):])
elif content.startswith('!addvoicechannel'):
await RestrictChanSuite.add_voice_channel(maybe_restrict_chan, content[len('!addvoicechannel '):])
elif content.startswith('!removevoicechannel'):
await RestrictChanSuite.remove_voice_channel(maybe_restrict_chan, content[len('!removevoicechannel '):])
return True
except:
print('could not find restrictchannelcommandline');
try:
command, chanName, name = content.split(' ')
chanName = 'R-' + chanName
except:
await message.channel.send('Invalid command: ' + message.content, delete_after = 5)
return
rschan = RestrictChanSuite.get_restrictchan(RestrictChanSuite.get_all_restrictchans(message.channel.guild), chanName.upper())
rschan_cli = RestrictChanSuite.get_cli(rschan)
if rschan:
if content.startswith('!addtextchannel'):
await rschan_cli.send(message.author.name + ' would like to add a text channel to this restricted group: ' + name + '. Would anyone like to take care of that?')
# remove a text channel from a hangout space.
elif content.startswith('!removetextchannel'):
await rschan_cli.send(message.author.name + ' would like to remove a text channel to this restricted group: ' + name + '. Would anyone like to take care of that?')
elif content.startswith('!addvoicechannel'):
await rschan_cli.send(message.author.name + ' would like to add a voice channel to this restricted group: ' + name + '. Would anyone like to take care of that?')
elif content.startswith('!removevoicechannel'):
await rschan_cli.send(message.author.name + ' would like to remove a voice channel to this restricted group: ' + name + '. Would anyone like to take care of that?')
await message.channel.send('We heard your request. Our moderators will respond to your request soon :)', delete_after = 5)
return True
else:
message.channel.send('There is no restricted channel called: ' + chanName + '! Try again! We hope to help you in some way!')
\ No newline at end of file
res_chan = AbstractChanSuite.is_cli(AbstractChanSuite.get_all_chans(message.guild, RestrictChan.channel_type), message.channel, RestrictChan.convener_role_name)
if not res_chan:
return False # Did not process commands
if content.startswith('!addtextchannel'):
await RestrictChanSuite.add_text_channel(res_chan, content[len('!addtextchannel '):])
elif content.startswith('!removetextchannel'):
await RestrictChanSuite.remove_text_channel(res_chan, content[len('!removetextchannel '):])
elif content.startswith('!addvoicechannel'):
await RestrictChanSuite.add_voice_channel(res_chan, content[len('!addvoicechannel '):])
elif content.startswith('!removevoicechannel'):
await RestrictChanSuite.remove_voice_channel(res_chan, content[len('!removevoicechannel '):])
return True
async def process_user_commands(message):
# Check if a valid command and respond accordingly if so.
# Return false if no command was processed.
# Send a success message and return true if a command was processed successfully.
content = message.content.lower()
message_parts = content.split(' ')
if len(message_parts) >= 3:
rschan = RestrictChanSuite.get_restrictchan(RestrictChanSuite.get_all_restrictchans(message.channel.guild),RestrictChan.channel_type +'-'+ message_parts[1])
rschan_cli = RestrictChanSuite.get_cli(rschan)
addchanname = '-'.join(message_parts[2:])
if rschan:
if content.startswith('!addtextchannel'):
await rschan_cli.send(message.author.name + ' would like to add a text channel to this restricted group: ' + addchanname + '. Would anyone like to take care of that?')
# remove a text channel from a hangout space.
elif content.startswith('!removetextchannel'):
await rschan_cli.send(message.author.name + ' would like to remove a text channel to this restricted group: ' + addchanname + '. Would anyone like to take care of that?')
elif content.startswith('!addvoicechannel'):
await rschan_cli.send(message.author.name + ' would like to add a voice channel to this restricted group: ' + addchanname + '. Would anyone like to take care of that?')
elif content.startswith('!removevoicechannel'):
await rschan_cli.send(message.author.name + ' would like to remove a voice channel to this restricted group: ' + addchanname + '. Would anyone like to take care of that?')
await message.channel.send('We heard your request. Our moderators will respond to your request soon :)', delete_after = 5)
return True
return False
async def process_commands(message):
return await RestrictChanSuite.process_cli_commands(message) or await RestrictChanSuite.process_user_commands(message)
\ No newline at end of file
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