class SettingsCommands: def __init__(self): self.db_proc = DatabaseProcessor() async def set_greeting_text(self, ctx, args): title = "" description = "" is_title = True for i in args: if i.startswith("-") and i.endswith("-") and is_title: title += i[1:-1] is_title = False elif i.startswith('-') and title == "": title += i[1:] + " " elif i.endswith('-') and description == "": title += i[:-1] is_title = False elif is_title: title += i + " " elif not is_title: description += i + " " description = description[:-1] self.db_proc().set_greeting(ctx.guild.id, title + "; " + description) await ctx.message.delete(delay=3) emb = BASIC_EMB.copy() emb.title = "Done" await ctx.send(embed=emb, delete_after=5) async def toggle_greeting_notification(self, ctx): """ Turn on or turn off greeting message """ guild_id = ctx.guild.id if self.db_proc.is_greeting_enabled(guild_id): is_enabled = False else: is_enabled = True self.db_proc.toggle_enabled_greeting(guild_id, is_enabled) message = f"Greeting is turned {'on' if is_enabled else 'off'}" await ctx.send(message)
class GuildEvents: def __init__(self): self.db_proc = DatabaseProcessor() async def on_bot_join(self, guild): self.db_proc.create_row_guild_settings(guild.id) async def on_bot_leave(self, guild): self.db_proc.remove_row_guild_settings(guild.id) async def on_member_join(self, member): guild = member.guild channel = guild.system_channel if guild.system_channel is not None else guild.text_channels[ 0] text = self.db_proc.get_greeting(guild.id).split("; ") emb = BASIC_EMB.copy() emb.title = text[0].format(user=member.display_name, server=guild.name, prefix=PREFIX) emb.description = text[1].format(user=member.mention, server=guild.name, prefix=PREFIX) if guild.id == PUB_ID: role = guild.get_role(DEFAULT_ROLE_ID) await member.add_roles(role) try: if self.db_proc.is_greeting_enabled(guild.id): await channel.send(embed=emb) except (Forbidden, ClientConnectionError): pass async def check_donate_lvl(self, before, after): if before.top_role < after.top_role: id = after.id role = after.top_role.name if role not in DONATE_LVLS.keys(): return lvl = DONATE_LVLS[role] if not self.db_proc.is_donator(id): who = 'member' unlimit = date.today() <= END_DAY self.db_proc.create_row_donators(who, id, unlimit, lvl) else: self.db_proc.update_donator_lvl(id, lvl) elif before.top_role > after.top_role: id = after.id role = after.top_role.name if self.db_proc.is_donator(id): if self.db_proc.is_unlimit(id): role = before.top_role await after.add_roles(role) else: if role not in DONATE_LVLS.keys(): self.db_proc.remove_row_donators(id) else: lvl = DONATE_LVLS[role] self.db_proc.update_donator_lvl(id, lvl)