Merge remote-tracking branch 'origin/master'

This commit is contained in:
Suwako Moriya 2020-04-06 11:31:40 +02:00
commit bc9c6cb5f9
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5
3 changed files with 19 additions and 21 deletions

View File

@ -80,24 +80,20 @@ class BaseClass:
async def parse_command(self, message):
"""Parse a command_text from received message and execute function
%git update
com_update(m..)
Parse message like `{prefix}{command_text} subcommand` and call class method `com_{subcommand}`.
:param message: message to parse
:type message: discord.Message"""
if message.content.startswith(
self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "")):
content = message.content.lstrip(
self.client.config["prefix"] + (self.config.command_text if self.config.command_text else ""))
command = self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "") + " "
if message.content.startswith(command):
content = message.content.split(" ", 1)[1]
sub_command, args, kwargs = self._parse_command_content(content)
sub_command = "com_" + sub_command
if self.auth(message.author):
if sub_command in dir(self):
await self.__getattribute__(sub_command)(message, args, kwargs)
else:
await self.command(message, [sub_command[4:]] + args, kwargs)
await self.command(message, args, kwargs)
else:
await self.unauthorized(message)
@ -112,19 +108,21 @@ class BaseClass:
:type content: str
:return: parsed arguments: [subcommand, [arg1, arg2, ...], [(option1, arg1), (option2, arg2), ...]]
:rtype: list[str, list, list]"""
:rtype: tuple[str, list, list]"""
if not len(content.split()):
return "", [], []
# Sub_command
sub_command = content.split()[0]
args_ = []
args_ = [sub_command]
kwargs = []
if len(content.split()) > 1:
# Remove subcommand
content = content.lstrip(sub_command)
# Take the other part of command_text
content = content.split(" ", 1)[1].replace("\"", "\"\"")
content = content.lstrip().replace("\"", "\"\"")
# Splitting around quotes
quotes = [element.split("\" ") for element in content.split(" \"")]
# Split all sub chains but brute chains and flat the resulting list
# Split all sub chains but raw chains and flat the resulting list
args = [item.split() if item[0] != "\"" else [item, ] for sublist in quotes for item in sublist]
# Second plating
args = [item for sublist in args for item in sublist]

View File

@ -18,14 +18,14 @@ class MainClass(BaseClassPython):
guild = self.client.get_guild(self.client.config.main_guild)
for i, member in enumerate(guild.members):
if len(member.roles) == 1:
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
guilds=[self.client.get_guild(
self.client.config.main_guild)]))
await member.add_roles(self.client.id.get_role(id_=self.config.new_role,
guilds=[self.client.get_guild(
self.client.config.main_guild)]))
if i % 50 == 0:
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
async def on_member_join(self, member):
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
guilds=[self.client.get_guild(
self.client.config.main_guild)]))
await member.add_roles(self.client.id.get_role(id_=self.config.new_role,
guilds=[self.client.get_guild(
self.client.config.main_guild)]))
await member.send(self.config.motd)

View File

@ -26,11 +26,11 @@ class MainClass(BaseClassPython):
return
if message.channel.id == self.config.listen_chan:
if message.content.lower() in self.config.passwords:
new_role = await self.client.id.get_role(id_=self.config.new_role, guilds=[message.channel.guild])
new_role = self.client.id.get_role(id_=self.config.new_role, guilds=[message.channel.guild])
if new_role in message.author.roles:
await message.author.remove_roles(new_role)
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
guild=[message.channel.guild]))
await message.author.add_roles(self.client.id.get_role(id_=self.config.accepted_role,
guild=[message.channel.guild]))
await message.author.send(self.config.succes_pm)
await message.channel.guild.get_channel(self.config.log_chan).send(
self.config.succes.format(user=message.author.mention))