async def set_welcome_role(self, ctx, *, role: discord.Role = None): """ Set welcome role """ guild_id = ctx.guild.id if not role: # error await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('<role>')) await self.logger.log('nickname_log', ctx.author, ctx.message, True) return role_id = role.id select = f"select role_id from welcome_role where guild_id='{guild_id}' and role_id='{role_id}' ;" fetched = database.fetch_one_line(select) if fetched: sql = f"update welcome_role set role_id='{role_id}' where guild_id='{guild_id}' and role_id='{role_id}' ;" else: sql = f"insert into welcome_role values ('{role_id}', '{guild_id}') ;" error = False logger("welcome::set_welcome_role", sql) try: database.execute_order(sql, []) except Exception as e: error = True # Log my change if error: await ctx.message.add_reaction('❌') else: await ctx.message.add_reaction('✅')
async def set_welcome(self, ctx, *, channel: discord.TextChannel = None): """ Set the welcome channel """ channel = channel or ctx.channel guild_id = ctx.guild.id error = False select = f"select * from welcome_channel where guild_id='{guild_id}' ;" fetched = database.fetch_one_line(select) if not fetched: sql = f"insert into welcome_channel values ('{channel.id}', '{guild_id}') ;" else: sql = f"update welcome_channel set channel_id='{channel.id}' where guild_id='{guild_id}' ;" try: database.execute_order(sql, []) except Exception as e: await ctx.channel.send( Utils.get_text(ctx.guild.id, "error_database_writing")) logger("welcome::set_welcome", f'{type(e).__name__} - {e}') error = True # Log my change if error: await ctx.message.add_reaction('❌') else: await ctx.message.add_reaction('✅')
async def set_utip_delay(self, ctx): guild_id = ctx.message.guild.id author = ctx.author await ctx.send( "Entrez le délai durant lequel le membre garde le rôle : ") check = lambda m: m.channel == ctx.channel and m.author == ctx.author msg = await self.bot.wait_for('message', check=check) message = msg.content sql = f"select delay from config_delay where guild_id='{guild_id}' and type_delay='utip_role' ;" try: delay = Utils.parse_time(message) except Exception as e: await ctx.message.add_reaction('❌') await ctx.channel.send( Utils.get_text(ctx.guild.id, "utip_delay_error").format(message)) return prev_galerie_delay = database.fetch_one_line(sql) if not prev_galerie_delay: sql = f"insert into config_delay (`delay`, `type_delay`, `guild_id`) values (?, 'utip_role', '{guild_id}')" else: sql = f"update config_delay set delay=? where guild_id='{guild_id}' and type_delay='utip_role' ;" try: database.execute_order(sql, [delay]) except Exception as e: logger("utip::set_utip_delay", f"{type(e).__name__} - {e}") await ctx.message.add_reaction('❌') else: await ctx.message.add_reaction('✅')
async def on_raw_reaction_add(self, payload): message_id = payload.message_id guild_id = payload.guild_id channel_id = payload.channel_id emoji = payload.emoji author_id = payload.user_id if author_id == self.bot.user.id: return if not str(emoji) in ["👍", "👎"]: return select_waiting = f"select user_id from utip_waiting where message_id='{message_id}' and status=0;" fetched_waiting = database.fetch_one_line(select_waiting) if not fetched_waiting: return user_id = int(fetched_waiting[0]) channel_selected = await self.bot.fetch_channel(channel_id) message_selected = await channel_selected.fetch_message(message_id) guild_select = message_selected.guild member_selected = guild_select.get_member(user_id) author_selected = guild_select.get_member(author_id) select_role = f"select role_id from utip_role where guild_id='{guild_id}' ;" fetched_role = database.fetch_one_line(select_role) if not fetched_role: await channel_selected.send( Utils.get_text(guild_id, "utip_role_undefined")) return role_utip = guild_select.get_role(int(fetched_role[0])) select_delay = ( "select delay from config_delay " + f"where guild_id='{guild_id}' and type_delay='utip_role' ;") fetched_delay = database.fetch_one_line(select_delay) if not fetched_delay: await channel_selected.send( Utils.get_text(guild_id, "utip_role_undefined")) return delay = int(fetched_delay[0]) embed = message_selected.embeds[0] colour = discord.Colour(0) if str(emoji) == "👍": update_waiting = ("update utip_waiting " + "set status=1 " + f"where message_id='{message_id}' ;") await self.give_role(member_selected, role_utip, delay) colour = colour.from_rgb(56, 255, 56) embed.set_footer(text=f"Accepté par {str(author_selected)}") feedback_message = ( ":white_check_mark: Demande validée ! " + f"Tu dispose du role de backers pendant **{Utils.format_time(delay)}**." + # ":arrow_right: Ton role prendra fin le **XX/XX/XXX** à **XX:XX**"+ "") else: update_waiting = ("update utip_waiting " + "set status=2 " + f"where message_id='{message_id}' ;") colour = colour.from_rgb(255, 71, 71) embed.set_footer(text=f"Refusé par {str(author_selected)}") feedback_message = ("Votre demande a été refusée." + "") database.execute_order(update_waiting) embed.colour = colour await message_selected.edit(embed=embed) await member_selected.send(feedback_message)
async def set_roledm_role(self, ctx, *, role: discord.Role = None): """ Set roledm role @params discord.Role role """ guild_id = ctx.guild.id if not role: # error await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('<role>')) await ctx.message.add_reaction('❌') return role_id = role.id sql = f"insert into roledm_role values ('{role_id}', '{guild_id}')" error = False try: database.execute_order(sql, []) except Exception as e: error = True # Log my change if error: await ctx.message.add_reaction('❌') else: await ctx.message.add_reaction('✅')
async def edit_rule(self, ctx: commands.Context, emoji_text: str = None): if not emoji_text: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('<emoji>')) await ctx.message.add_reaction('❌') return custom_emoji_id = Utils.is_custom_emoji(emoji_text) sql = f"SELECT * FROM rules_table WHERE (emoji_text='{emoji_text}' OR emoji_id='{custom_emoji_id}') and guild_id=?;" fetched = database.fetch_one_line(sql, [ctx.guild.id]) if not fetched: await ctx.send( Utils.get_text(ctx.guild.id, "rules_not_found").format(emoji_text)) await ctx.message.add_reaction('❌') return await ctx.send(Utils.get_text(ctx.guild.id, "ask_message")) msg = await self.bot.wait_for( 'message', check=lambda m: m.channel == ctx.channel and m.author == ctx.author ) message = msg.content sql = f"UPDATE rules_table SET rule=? WHERE (emoji_text='{emoji_text}' OR emoji_id='{custom_emoji_id}') and guild_id=?;" try: database.execute_order(sql, [message, ctx.guild.id]) await ctx.message.add_reaction('✅') except Exception as e: logger("rules::edit_rule", f"{type(e).__name__} - {e}") await ctx.send( Utils.get_text(ctx.guild.id, "rules_edited").format(emoji_text))
async def set_birthday_channel(self, ctx, channel: discord.TextChannel = None): """Save channel where birthday will be wished. Param: channel ID""" guild_id = ctx.guild.id channel = channel or ctx.channel channel_id = channel.id sql = f"SELECT channel_id FROM birthday_channel WHERE guild_id='{guild_id}'" is_already_set = database.fetch_one_line(sql) if is_already_set: sql = f"UPDATE birthday_channel SET channel_id='{channel_id}' WHERE guild_id='{guild_id}'" else: sql = f"INSERT INTO birthday_channel VALUES ('{channel_id}', '{guild_id}') ;" try: database.execute_order(sql, []) except Exception as e: await ctx.send( Utils.get_text(ctx.guild.id, 'error_database_writing')) logger("birthday::set_birthday_channel", f"{type(e).__name__} - {e}") await ctx.send( Utils.get_text(ctx.guild.id, 'birthday_channel_set').format(f'<#{channel_id}>'))
async def do_load(self, ctx, *, cog: str): """ Load cogs for this guild """ author = ctx.author guild_id = ctx.guild.id if not cog: await ctx.message.add_reaction('❌') await ctx.send("Paramètre <cog> obligatoire.") return cog = cog.lower() try: select = ("select status " "from config_cog " + "where " + "cog=? " + " and " + "guild_id=? ;" + "") fetched = database.fetch_one_line(select, [cog, guild_id]) sql = "" if fetched: status = fetched[0] if status == 0: sql = "update config_cog set status=1 where cog=? and guild_id=? ;" else: sql = "insert into config_cog (`cog`, `guild_id`, `status`) values (?,?,1) ;" if len(sql): database.execute_order(sql, [cog, guild_id]) except Exception as e: await ctx.message.add_reaction('❌') logger("loader::do_load", f"{type(e).__name__} - {e}") else: await ctx.message.add_reaction('✅')
async def set_first_emoji(self, ctx: commands.Context, emoji_input: str): """ Set the first emoji for the timer """ guild_id = ctx.guild.id try: emoji = await Utils.get_emoji(ctx, emoji_input) except Exception as e: logger("timer::set_first_emoji", f"{type(e).__name__} - {e}") await ctx.send( Utils.get_text(guild_id, "timer_not_emoji").format(emoji_input)) return select = "select emoji from timer_first_emoji where guild_id=? ;" fetched = database.fetch_one_line(select, [guild_id]) if not fetched: order = "insert into timer_first_emoji (emoji, guild_id) values (?, ?) ;" else: order = "update timer_first_emoji set emoji=? where guild_id=? ;" try: database.execute_order(order, [str(emoji), guild_id]) except Exception as e: logger("timer::set_first_emoji", f"{type(e).__name__} - {e}") return await ctx.send( Utils.get_text(guild_id, "timer_set_first_emoji").format(str(emoji))) await ctx.message.delete(delay=0.5)
async def set_do_first_emoji(self, ctx: commands.Context, true_or_false: str): """ Toggle the first emoji for the timer """ guild_id = ctx.guild.id type_do = "first_emoji" do_first_emoji = (true_or_false.lower() == "true") select = "select do from config_do where type_do=? and guild_id=? ;" fetched = database.fetch_one_line(select, [type_do, guild_id]) if not fetched: order = "insert into config_do (do, type_do, guild_id) values (?, ?, ?) ;" else: order = "update config_do set do=? where type_do=? and guild_id=? ;" try: database.execute_order(order, [do_first_emoji, type_do, guild_id]) except Exception as e: logger("timer::set_do_first_emoji", f"{type(e).__name__} - {e}") return if (do_first_emoji): await ctx.send(Utils.get_text(guild_id, "timer_set_do_first_emoji")) else: await ctx.send( Utils.get_text(guild_id, "timer_set_do_first_emoji_not")) await ctx.message.delete(delay=0.5)
async def set_message(self, ctx: commands.Context, *message: str): """ Set the end message for the timer """ guild_id = ctx.guild.id end_message = ' '.join(part for part in message) if len(end_message) > 512: await ctx.send( Utils.get_text(guild_id, "error_string_max_length").format(512)) return select = "select end_message from timer_end_message where guild_id=? ;" fetched = database.fetch_one_line(select, [guild_id]) if not fetched: order = "insert into timer_end_message (end_message, guild_id) values (?, ?) ;" else: order = "update timer_end_message set end_message=? where guild_id=? ;" try: database.execute_order(order, [str(end_message), guild_id]) except Exception as e: logger("timer::set_message", f"{type(e).__name__} - {e}") return await ctx.send( Utils.get_text(guild_id, "timer_set_end_message").format(str(end_message))) await ctx.message.delete(delay=0.5)
async def set_vote_type(self, ctx, message_id: str = None, type_vote: str = None): """ Set a type for a vote message """ author = ctx.author guild_id = ctx.guild.id if not message_id: await ctx.send(Utils.get_text(ctx.guild.id, "error_no_parameter").format('<messageID>')) return try: message_id = int(message_id) except Exception as e: await ctx.send(Utils.get_text(ctx.guild.id, "error_no_parameter").format('<messageID>')) return if not type_vote: type_vote = "vote" sql = f"update vote_message set vote_type=? where message_id=?" try: database.execute_order(sql, [type_vote, message_id]) except Exception as e: await ctx.send(Utils.get_text(ctx.guild.id, "error_occured")) await ctx.message.add_reaction('❌') await self.logger.log('vote_log', author, ctx.message, True) return await ctx.message.add_reaction('✅') await self.logger.log('vote_log', author, ctx.message, False) await ctx.message.delete(delay=0.5)
async def set_vote_channel(self, ctx, channel_id: str = None): """ Set a channel to ping end of phases """ author = ctx.author guild_id = ctx.guild.id channel_id = channel_id or ctx.channel.id guild_id = ctx.guild.id try: channel_id = int(channel_id) except Exception as e: await ctx.send(Utils.get_text(ctx.guild.id, "error_no_parameter").format('<channelID>')) await ctx.message.add_reaction('❌') return select = f"select * from vote_channel where guild_id='{guild_id}' ;" fetched = database.fetch_one_line(select) if fetched: sql = f"update vote_channel set channel_id='{channel_id}' where guild_id='{guild_id}'" else: sql = f"insert into vote_channel values ('{channel_id}', '{guild_id}') ;" try: database.execute_order(sql) except Exception as e: await ctx.send(Utils.get_text(ctx.guild.id, "error_occured")) await ctx.message.add_reaction('❌') return await ctx.message.add_reaction('✅')
async def close_all_vote(self, ctx, message_id: str = None): """ Close all vote """ author = ctx.author guild_id = ctx.guild.id author = ctx.author guild_id = ctx.guild.id select = f"select message_id, month, year from vote_message where guild_id='{guild_id}' and closed <> 3 ;" fetched = database.fetch_all_line(select) if fetched: for message in fetched: message_id = message[0] update = f"update vote_message set closed=3 where message_id='{message_id}' ;" try: vote_msg = await ctx.channel.fetch_message(message_id) except Exception as e: if type(e).__name__ == "NotFound": await ctx.send(Utils.get_text(ctx.guild.id, "vote_error_message_not_found")) elif type(e).__name__ == "Forbidden": await ctx.send(Utils.get_text(ctx.guild.id, "error_permission_denied")) else: await ctx.send(Utils.get_text(ctx.guild.id, "error_unknown_error").format(type(e).__name__, e)) await self.logger.log('vote_log', author, ctx.message, True) await ctx.message.add_reaction('❌') return embed = vote_msg.embeds[0] database.execute_order(update) colour = discord.Colour(0) colour = colour.from_rgb(255, 71, 71) embed.colour = colour embed.set_footer(text=f"{message[1]}/{message[2]} Phase de vote terminée") await vote_msg.edit(embed=embed) await ctx.message.add_reaction('✅')
async def reset_birthday(self, ctx, member: discord.Member = None): guild_id = ctx.guild.id error = False member = member or ctx.author if member is None: await ctx.send("Le paramètre <member> est obligatoire.") await ctx.message.add_reaction('❌') await self.logger.log('birthday_log', ctx.author, ctx.message, True) return sql = f"SELECT user_id FROM birthday_user WHERE user_id={member.id} and guild_id={ctx.guild.id}" member_in_db = database.fetch_one_line(sql) if not member_in_db: await ctx.send( Utils.get_text(ctx.guild.id, "error_user_not_found").format( member.mention, 'birthday_user')) return sql = f"DELETE FROM birthday_user WHERE user_id='{member.id}' and guild_id={ctx.guild.id} ;" try: database.execute_order(sql, []) except Exception as e: error = True await ctx.send( Utils.get_text(ctx.guild.id, 'error_database_writing')) logger("birthday::reset_birthday", f"{type(e).__name__} - {e}") await ctx.send( Utils.get_text(ctx.guild.id, 'birthday_reset').format(member.mention)) await self.logger.log('birthday_log', ctx.author, ctx.message, error)
async def update_welcomeuser(self, ctx): guild_id = ctx.message.guild.id member = ctx.author select = f"select role_id from welcome_role where guild_id='{guild_id}'" fetched_all = database.fetch_all_line(select) if not fetched_all: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_role_defined")) return for fetched in fetched_all: role_id = int(fetched[0]) # get the role role = ctx.guild.get_role(role_id) # write every member for member in role.members: # sql insert = ( "insert into welcome_user (`user_id`, `role_id`, `welcomed_at`, `guild_id`)" + f"values ('{member.id}', {role_id},{math.floor(time.time())}, '{guild_id}') ;" ) try: database.execute_order(insert) except Exception as e: logger("welcome::update_welcomeuser", f'{type(e).__name__} - {e}') await ctx.message.add_reaction('✅')
async def set_welcome_message(self, ctx, role: discord.Role = None): guild_id = ctx.message.guild.id member = ctx.author if not role: await ctx.message.add_reaction('❌') await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('<role>')) return await ctx.send(Utils.get_text(ctx.guild.id, "ask_welcome_message")) check = lambda m: m.channel == ctx.channel and m.author == ctx.author msg = await self.bot.wait_for('message', check=check) message = msg.content sql = f"select message from welcome_message where guild_id='{guild_id}' and role_id={role.id}; " prev_galerie_message = database.fetch_one_line(sql) if not prev_galerie_message: sql = f"INSERT INTO welcome_message (`message`,`role_id`,`guild_id`) VALUES (?, {role.id},'{guild_id}') ;" else: sql = f"update welcome_message set message=? where guild_id='{guild_id}' and role_id={role.id} ;" logger("welcome::set_welcome_message", sql) try: database.execute_order(sql, [message]) except Exception as e: logger("welcome::set_welcome_message", f"{type(e).__name__} - {e}") await ctx.channel.send( Utils.get_text(ctx.guild.id, "display_new_message").format(message))
async def update_nickname(self, ctx): author = ctx.author guild_id = ctx.guild.id try: for member in ctx.guild.members: if member.nick: select = ( f"select nickname from nickname_current" + f" where guild_id='{guild_id}' and member_id='{member.id}' ;" ) fetched = database.fetch_one_line(select) sql = "" if not fetched: sql = ( f"insert into nickname_current values ('{member.id}', " + f" '{guild_id}' , '{member.nick}') ;") elif not member.nick == fetched[0]: # Impossibru sql = ( f"update nickname_current set nickname='{member.nick}'" + f" where guild_id='{guild_id}' and member_id='{member.id}' ;" ) if len(sql): database.execute_order(sql) await ctx.send(Utils.get_text(ctx.guild.id, "nickname_updated")) except Exception as e: await ctx.send( Utils.get_text(ctx.guild.id, "error_occured").format(f"{type(e).__name__}", f"{e}")) logger("nickname::update_nickname", f"{type(e).__name__} - {e}")
async def create_vote(self, ctx, *args): """ Create a vote """ author = ctx.author guild_id = ctx.guild.id # date today = date.today() month = str(today.month) if today.month > 9 else "0" + str(today.month) year = str(today.year) # reason reason = ' '.join(arg for arg in args) reason = reason or "Vote pour le changement de nom du rôle des membres" # description description = "Aucune description" error = False # Embed capturing our vote embed = self.create_embed(reason, description, month, year) poll = await ctx.send(content=None, embed=embed) # insert into vote_message values ('message_id', 'channel_id', 'month', 'year', 'closed', 'author_id', guild_id', 'vote_type') sql = f"insert into vote_message (`message_id`, `channel_id`, `month`, `year`, `closed`, `author_id`, `guild_id`, `vote_type`) values ('{poll.id}', '{ctx.channel.id}', '{month}', '{year}', 0, '{author.id}', '{guild_id}', 'vote')" database.execute_order(sql, []) started_at = math.floor(time.time()) sql = f"insert into vote_time (`message_id`, `started_at`, `proposition_ended_at`, `edit_ended_at`, `vote_ended_at`, `guild_id`) values ('{poll.id}', '{started_at}', NULL, NULL, NULL, '{guild_id}') ;" database.execute_order(sql, []) # await ctx.send (f"`{sql}`") await self.logger.log('vote_log', author, ctx.message, error) await ctx.message.delete(delay=0.5)
async def set_gallery_delay(self, ctx, delay: str = None): author = ctx.author guild_id = ctx.message.guild.id try: if not delay.isnumeric(): delay = Utils.parse_time(delay) type_delay = "gallery" select = ("select delay from config_delay" + " where " + f" `type_delay`=? and `guild_id`='{guild_id}'" + "") fetched = database.fetch_one_line(select, [type_delay]) if fetched: order = ("update config_delay" + " set `delay`=? " + " where " + f" `type_delay`=? and `guild_id`='{guild_id}'" + "") else: order = ("insert into config_delay" + " (`delay`, `type_delay`, `guild_id`) " + " values " + f" (?, ?, '{guild_id}')" + "") database.execute_order(order, [delay, type_delay]) await ctx.message.add_reaction('✅') except Exception as e: logger("gallery::set_gallery_delay", f" {type(e).__name__} - {e}") error = True await ctx.message.add_reaction('❌') await self.logger.log('config_log', author, ctx.message, error)
async def set_nickname_cd(self, ctx): author = ctx.author guild_id = ctx.guild.id error = False ask = await ctx.send(Utils.get_text(guild_id, "nickname_new_delay")) check = lambda m: m.channel == ctx.channel and m.author == ctx.author msg = await self.bot.wait_for('message', check=check) old_delay = Utils.nickname_delay(guild_id) try: delay = Utils.parse_time(msg.content) except Exception as e: error = True await ctx.send(f"{type(e).__name__} -{e}") else: if not old_delay: sql = "insert into config_delay (`delay`,`type_delay`,`guild_id`) values (?,?,?) ;" else: sql = "update config_delay set delay=? where type_delay=? and guild_id=? ;" try: database.execute_order(sql, [delay, 'nickname', guild_id]) except Exception as e: error = True await ctx.send(f"{type(e).__name__} -{e}") # type delay = nickname if not error: await ctx.message.add_reaction('✅') await msg.add_reaction('✅') else: await ctx.message.add_reaction('❌') await msg.add_reaction('❌') await ctx.message.delete(delay=1.5) await ask.delete(delay=1.5) await msg.delete(delay=1.5) await self.logger.log('nickname_log', author, ctx.message, error) await self.logger.log('nickname_log', author, msg, error)
async def set_do(self, ctx, type_do: str = None, do: str = None): guild_id = ctx.message.guild.id author = ctx.author if not type_do: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('**<type_do>**')) return if not do: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('**<do>**')) return error = False try: select = ("select do from config_do" + " where " + f" `type_do`=? and `guild_id`='{guild_id}'" + "") fetched = database.fetch_one_line(select, [type_do]) if fetched: order = ("update config_do" + " set `do`=? " + " where " + f" `type_do`=? and `guild_id`='{guild_id}'" + "") else: order = ("insert into config_do" + " (`do`, `type_do`, `guild_id`) " + " values " + f" (?, ?, '{guild_id}')" + "") database.execute_order(order, [do, type_do]) await ctx.message.add_reaction('✅') except Exception as e: logger("configuration::set_do", f" {type(e).__name__} - {e}") error = True await ctx.message.add_reaction('❌') await self.logger.log('config_log', author, ctx.message, error)
async def blacklist_domain(self, ctx: commands.Context, domain: str = None): if not domain: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format("domain")) return if "." in domain: await ctx.send(Utils.get_text(ctx.guild.id, "source_wrong_format")) return sql = f"SELECT domain FROM source_domain WHERE guild_id='{ctx.guild.id}' ;" if domain in [domain[0] for domain in database.fetch_all_line(sql)]: await ctx.send( Utils.get_text( ctx.guild.id, "source_domain_already_blacklisted").format(domain)) await ctx.message.add_reaction('❌') return sql = f"INSERT INTO source_domain VALUES ('{domain}', '{ctx.guild.id}') ;" try: database.execute_order(sql, []) await ctx.message.add_reaction('✅') except Exception as e: logger("source::blacklist_domain", f"{type(e).__name__} - {e}") await ctx.message.add_reaction('❌') return await ctx.send( Utils.get_text(ctx.guild.id, "source_domain_blacklisted").format(domain))
async def remove_domain(self, ctx: commands.Context, domain: str = None): if not domain: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format("domain")) return sql = f"SELECT domain FROM source_domain WHERE guild_id='{ctx.guild.id}' ;" if domain not in [ domain[0] for domain in database.fetch_all_line(sql) ]: await ctx.send( Utils.get_text(ctx.guild.id, "source_domain_not_found").format(domain)) await ctx.message.add_reaction('❌') return sql = f"DELETE FROM source_domain WHERE domain='{domain}' and guild_id='{ctx.guild.id}' ;" try: database.execute_order(sql, []) await ctx.message.add_reaction('✅') except Exception as e: logger("source::remove_domain", f"{type(e).__name__} - {e}") await ctx.message.add_reaction('❌') return await ctx.send( Utils.get_text(ctx.guild.id, "source_domain_removed").format(domain))
def _add_next_timer(self, member_id: int, guild_id: int): # Auto rename user after X minutes if they havent renamed themselves (see Cron) sql = "SELECT timer FROM nickname_next_timer WHERE guild_id=? ;" response = database.fetch_one_line(sql, [guild_id]) timer = response[0] if response else 15 sql = "INSERT INTO nickname_next_limit VALUES (?, ?, datetime(?)) ;" limit = datetime.now() + timedelta(minutes=timer) database.execute_order(sql, [member_id, guild_id, limit])
async def remove_emoji_to_channel_link( self, ctx: commands.Context, emoji: typing.Union[discord.Emoji, discord.PartialEmoji, str]): sql = "DELETE FROM highlight_emoji_channel WHERE emoji_id=? AND guild_id=? ;" emoji_id = emoji.id if isinstance(emoji, (discord.Emoji, discord.PartialEmoji)) else emoji database.execute_order(sql, [emoji_id, ctx.guild.id]) await ctx.send( Utils.get_text(ctx.guild.id, 'highlight_emoji_channel_removed').format(emoji))
async def ban_command_role(self, ctx, command: str = None, role: discord.Role = None, timer: str = None): guild_id = ctx.message.guild.id author = ctx.author # Check if command exists all_commands = self.bot.commands cont_after = False for garden_command in all_commands: if command == garden_command.name or command in garden_command.aliases: command = garden_command.name cont_after = True if cont_after: break if not cont_after: await ctx.send( Utils.get_text(ctx.guild.id, "error_unknown_command").format(command)) await ctx.message.add_reaction('❌') return # Check if user exists if not role: await ctx.send( Utils.get_text(ctx.guild.id, "error_no_parameter").format('User')) await ctx.message.add_reaction('❌') return # Parse time timestamp = None if timer: timestamp = math.floor(time.time()) + Utils.parse_time(timer) if not timestamp: timestamp = "NULL" # Insert/Update # CREATE TABLE IF NOT EXISTS `ban_command_user` (`command` VARCHAR(256) NOT NULL, `until` INTEGER, `user_id` VARCHAR(256) NOT NULL, `guild_id` VARCHAR(256) NOT NULL, PRIMARY KEY (`command`, `user_id`, `guild_id`)) ; select = f"select until from ban_command_role where command='{command}' and role_id='{role.id}' and guild_id='{guild_id}' ;" fetched = database.fetch_one_line(select) if fetched: sql = f"update ban_command_role set until={timestamp} where command='{command}' and role_id='{role.id}' and guild_id='{guild_id}' ;" else: sql = f"insert into ban_command_role values ('{command}', {timestamp}, '{role.id}', '{guild_id}');" try: database.execute_order(sql) await ctx.send( Utils.get_text(ctx.guild.id, "bancommand_user_banned_command").format( role.name, command, timer or Utils.get_text( ctx.guild.id, "bancommand_permanent"))) await ctx.message.add_reaction('✅') except Exception as e: logger("bancommand::ban_command_role", f'{type(e).__name__} - {e}') await ctx.message.add_reaction('❌')
async def add_source_channel(self, ctx, channel_id: int = None): channel_id = channel_id or ctx.channel.id sql = f"INSERT INTO source_channel VALUES ('{channel_id}', '{ctx.guild.id}') ;" try: database.execute_order(sql, []) except Exception as e: await ctx.send( Utils.get_text(ctx.guild.id, 'error_database_writing')) logger("source::add_source_channel", f"{type(e).__name__} - {e}") await ctx.send( Utils.get_text(ctx.guild.id, 'source_channel_added').format(f'<#{channel_id}>'))
async def reset_nickname(self, ctx, member: discord.Member = None): member = member or ctx.author guild_id = ctx.guild.id sql = f"delete from last_nickname where guild_id='{guild_id}' and member_id='{member.id}'" error = False try: database.execute_order(sql, []) await ctx.message.add_reaction('✅') except Exception as e: logger("nickname::reset_nickname", f"{type(e).__name__} - {e}") await ctx.message.add_reaction('❌') error = True await self.logger.log('nickname_log', ctx.author, ctx.message, error)
def set_log_channel(table: str, channel_id: int, guild_id: int): sql = f"SELECT channel_id FROM {table} WHERE guild_id='{guild_id}'" is_already_set = database.fetch_one_line(sql) if is_already_set: sql = f"UPDATE {table} SET channel_id='{channel_id}' WHERE guild_id='{guild_id}'" else: sql = f"INSERT INTO {table} VALUES ('{channel_id}', '{guild_id}') ;" try: database.execute_order(sql, []) except Exception as e: logger("Utils::set_log_channel", f"{type(e).__name__} - {e}") return False return True