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)
async def predicate(ctx): is_donator_guild = ctx.guild.id in DatabaseProcessor().get_donators_guilds() is_donator_member = ctx.author.id in DatabaseProcessor().get_donators_members() if (is_donator_guild or is_donator_member or date.today() <= END_DAY or DEBUG or await ctx.bot.is_owner(ctx.author)): return True else: raise NotDonator()
async def on_ready(self): db_p = DatabaseProcessor() guilds = [i.id for i in self.guilds] wr_guilds = [i[0] for i in db_p.get_guilds()] for guild in guilds: if not guild in wr_guilds: db_p.create_row_guild_settings(guild) wr_guilds = [i[0] for i in db_p.get_guilds()] for guild in wr_guilds: if guild not in guilds: db_p.remove_row_guild_settings(guild) self.loop.create_task(self.dynamic_activity()) print("Bot on-line")
def __init__(self): self.db_proc = DatabaseProcessor()
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)
def close_database(): DatabaseProcessor().db.close()
def __init__(self, bot): super().__init__() self.bot = bot self.db_proc = DatabaseProcessor() self.system = SystemCommands()