Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
bc9c6cb5f9
@ -80,24 +80,20 @@ class BaseClass:
|
|||||||
|
|
||||||
async def parse_command(self, message):
|
async def parse_command(self, message):
|
||||||
"""Parse a command_text from received message and execute function
|
"""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}`.
|
Parse message like `{prefix}{command_text} subcommand` and call class method `com_{subcommand}`.
|
||||||
|
|
||||||
:param message: message to parse
|
:param message: message to parse
|
||||||
:type message: discord.Message"""
|
:type message: discord.Message"""
|
||||||
if message.content.startswith(
|
command = self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "") + " "
|
||||||
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]
|
||||||
content = message.content.lstrip(
|
|
||||||
self.client.config["prefix"] + (self.config.command_text if self.config.command_text else ""))
|
|
||||||
sub_command, args, kwargs = self._parse_command_content(content)
|
sub_command, args, kwargs = self._parse_command_content(content)
|
||||||
sub_command = "com_" + sub_command
|
sub_command = "com_" + sub_command
|
||||||
if self.auth(message.author):
|
if self.auth(message.author):
|
||||||
if sub_command in dir(self):
|
if sub_command in dir(self):
|
||||||
await self.__getattribute__(sub_command)(message, args, kwargs)
|
await self.__getattribute__(sub_command)(message, args, kwargs)
|
||||||
else:
|
else:
|
||||||
await self.command(message, [sub_command[4:]] + args, kwargs)
|
await self.command(message, args, kwargs)
|
||||||
else:
|
else:
|
||||||
await self.unauthorized(message)
|
await self.unauthorized(message)
|
||||||
|
|
||||||
@ -112,19 +108,21 @@ class BaseClass:
|
|||||||
:type content: str
|
:type content: str
|
||||||
|
|
||||||
:return: parsed arguments: [subcommand, [arg1, arg2, ...], [(option1, arg1), (option2, arg2), ...]]
|
: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()):
|
if not len(content.split()):
|
||||||
return "", [], []
|
return "", [], []
|
||||||
# Sub_command
|
# Sub_command
|
||||||
sub_command = content.split()[0]
|
sub_command = content.split()[0]
|
||||||
args_ = []
|
args_ = [sub_command]
|
||||||
kwargs = []
|
kwargs = []
|
||||||
if len(content.split()) > 1:
|
if len(content.split()) > 1:
|
||||||
|
# Remove subcommand
|
||||||
|
content = content.lstrip(sub_command)
|
||||||
# Take the other part of command_text
|
# Take the other part of command_text
|
||||||
content = content.split(" ", 1)[1].replace("\"", "\"\"")
|
content = content.lstrip().replace("\"", "\"\"")
|
||||||
# Splitting around quotes
|
# Splitting around quotes
|
||||||
quotes = [element.split("\" ") for element in content.split(" \"")]
|
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]
|
args = [item.split() if item[0] != "\"" else [item, ] for sublist in quotes for item in sublist]
|
||||||
# Second plating
|
# Second plating
|
||||||
args = [item for sublist in args for item in sublist]
|
args = [item for sublist in args for item in sublist]
|
||||||
|
@ -18,14 +18,14 @@ class MainClass(BaseClassPython):
|
|||||||
guild = self.client.get_guild(self.client.config.main_guild)
|
guild = self.client.get_guild(self.client.config.main_guild)
|
||||||
for i, member in enumerate(guild.members):
|
for i, member in enumerate(guild.members):
|
||||||
if len(member.roles) == 1:
|
if len(member.roles) == 1:
|
||||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
await member.add_roles(self.client.id.get_role(id_=self.config.new_role,
|
||||||
guilds=[self.client.get_guild(
|
guilds=[self.client.get_guild(
|
||||||
self.client.config.main_guild)]))
|
self.client.config.main_guild)]))
|
||||||
if i % 50 == 0:
|
if i % 50 == 0:
|
||||||
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
|
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
|
||||||
|
|
||||||
async def on_member_join(self, member):
|
async def on_member_join(self, member):
|
||||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
await member.add_roles(self.client.id.get_role(id_=self.config.new_role,
|
||||||
guilds=[self.client.get_guild(
|
guilds=[self.client.get_guild(
|
||||||
self.client.config.main_guild)]))
|
self.client.config.main_guild)]))
|
||||||
await member.send(self.config.motd)
|
await member.send(self.config.motd)
|
||||||
|
@ -26,11 +26,11 @@ class MainClass(BaseClassPython):
|
|||||||
return
|
return
|
||||||
if message.channel.id == self.config.listen_chan:
|
if message.channel.id == self.config.listen_chan:
|
||||||
if message.content.lower() in self.config.passwords:
|
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:
|
if new_role in message.author.roles:
|
||||||
await message.author.remove_roles(new_role)
|
await message.author.remove_roles(new_role)
|
||||||
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
await message.author.add_roles(self.client.id.get_role(id_=self.config.accepted_role,
|
||||||
guild=[message.channel.guild]))
|
guild=[message.channel.guild]))
|
||||||
await message.author.send(self.config.succes_pm)
|
await message.author.send(self.config.succes_pm)
|
||||||
await message.channel.guild.get_channel(self.config.log_chan).send(
|
await message.channel.guild.get_channel(self.config.log_chan).send(
|
||||||
self.config.succes.format(user=message.author.mention))
|
self.config.succes.format(user=message.author.mention))
|
||||||
|
Loading…
Reference in New Issue
Block a user