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 remove_proposition(self, ctx, message_id_vote_type: str = None): """ Remove a proposition """ if not message_id_vote_type: # search for the lastest vote in that channel select = f"select message_id from vote_message where channel_id={ctx.channel.id} and closed=0" fetched = database.fetch_one_line(select) if not fetched: await ctx.send(Utils.get_text(ctx.guild.id, "vote_error_message_not_found")) await self.logger.log('vote_log', ctx.author, ctx.message, True) await ctx.message.add_reaction('❌') return message_id = fetched[0] else: # is it a message_id or vote_type try: message_id = int(message_id_vote_type) except Exception as e: logger ("vote::remove_proposition", f"{type(e).__name__} - {e}") # vote_type select = f"select message_id from vote_message where guild_id='{ctx.guild.id}' and closed=0 and vote_type=?" fetched = database.fetch_one_line(select, [message_id_vote_type]) if not fetched: await ctx.send(Utils.get_text(ctx.guild.id, "vote_error_message_not_found")) await self.logger.log('vote_log', ctx.author, ctx.message, True) await ctx.message.add_reaction('❌') return message_id = fetched[0] # Get proposition and handle it await self.handle_result(ctx, message_id, "remove_proposition", False)
async def rename_warn_task(bot): try: for guild in bot.guilds: guild_id = guild.id if not Utils.is_loaded("nickname", guild_id): continue sql = "SELECT member_id, timer_limit FROM nickname_next_limit WHERE guild_id=? ;" response = database.fetch_all_line(sql, [guild_id]) for data in response: limit = time.mktime( datetime.strptime(data[1], '%Y-%m-%d %H:%M:%S').timetuple()) duration = math.floor((limit - time.time())) if duration > 0: continue member = guild.get_member(int(data[0])) # Warn user and punish if already warned sql = "SELECT * FROM nickname_next_warn WHERE member_id=? AND guild_id=? ;" response = database.fetch_one_line(sql, [member.id, guild_id]) # If user has already been warned, hard rename if response: nickname = get_random_nickname(guild_id) or Utils.get_text( guild_id, "nickname_troll_nickname") await member.edit(nick=nickname) # write in db last_time select = f"SELECT * FROM last_nickname WHERE guild_id='{guild_id}' AND member_id='{member.id}'" fetched = database.fetch_one_line(select) if not fetched: sql = f"INSERT INTO last_nickname VALUES ('{member.id}', '{guild_id}', datetime('{datetime.now()}'))" else: sql = f"UPDATE last_nickname SET last_change=datetime('{datetime.now()}') WHERE member_id='{member.id}' AND guild_id='{guild_id}'" database.execute_order(sql, []) # write in db current nickanme select = f"SELECT * FROM nickname_current WHERE guild_id='{guild_id}' AND member_id='{member.id}' ;" fetched = database.fetch_one_line(select) if not fetched: sql = f"INSERT INTO nickname_current VALUES ('{member.id}', '{guild_id}', ?) ;" else: sql = f"UPDATE nickname_current SET nickname=? WHERE member_id='{member.id}' AND guild_id='{guild_id}' ;" database.execute_order(sql, [nickname]) # Soft rename and add a warn else: nickname = Utils.get_text(guild_id, "nickname_troll_nickname") await member.edit(nick=nickname) sql = "INSERT INTO nickname_next_warn VALUES (?, ?) ;" database.execute_order(sql, [member.id, guild_id]) # Delete limit record sql = "DELETE FROM nickname_next_limit WHERE member_id=? AND guild_id=? ;" database.execute_order(sql, [member.id, guild_id]) except Exception as e: logger("_Cron::rename_warn_task", f"rename_warn_task {type(e).__name__} - {e}")
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 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 log(self, db, member, message, error, params=None): guild_id = message.channel.guild.id sql = f"select channel_id from {db} where guild_id='{guild_id}'" db_log_channel = database.fetch_one_line(sql) if not db_log_channel: # log_channel = message.channel return # if not log_channel don't log else: log_channel = await self.bot.fetch_channel(int(db_log_channel[0])) colour = discord.Colour(0) colour = colour.from_rgb(176, 255, 176) if error: colour = colour.from_rgb(255, 125, 125) embed = discord.Embed(colour=colour) embed.set_author(icon_url=member.avatar_url, name=str(member)) embed.description = message.content embed.timestamp = datetime.utcnow() embed.set_footer(text=f"ID: {message.id}") if params and "url_to_go" in params: embed.description = embed.description + "\njumpto: " + params[ "url_to_go"] try: await log_channel.send(content=None, embed=embed) except Exception as e: logger("logs::log", f" {type(e).__name__} - {e}")
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 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_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 on_member_update(self, before, after): # guild id guild_id = before.guild.id if not Utils.is_loaded("roledm", guild_id): return # all roles to listen select = f"select role_id from roledm_role where guild_id='{guild_id}'" fetched = database.fetch_all_line(select) for line in fetched: role_id = line[0] if (not Utils.has_role(before, role_id) and Utils.has_role(after, role_id)): # The member obtained the role logger("roledm::on_member_update", 'The member obtained the role') select = f"select message from roledm_message where guild_id='{guild_id}'and role_id='{role_id}' ;" fetched = database.fetch_one_line(select) if fetched: message = (fetched[0]).replace("$member", before.mention).replace( "$role", f"<@&{role_id}>") else: message = Utils.get_text( guild_id, 'welcome_no_message').format(before.mention) # send await before.send(message)
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 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}")
def is_banned(command, member, guild_id): # admin can't be blocked if is_admin(member): return False # ban user select = f"select until from ban_command_user where guild_id='{guild_id}' and user_id='{member.id}' and command='{command}' ;" fetched = database.fetch_one_line(select) if fetched: try: until = int(fetched[0]) except Exception as e: logger("Utils::is_banned", f"{type(e).__name__} - {e}") return True if until > math.floor(time.time()): # still ban return True # ban role select = f"select until,role_id from ban_command_role where guild_id='{guild_id}' and command='{command}' ;" fetched = database.fetch_all_line(select) if fetched: for line in fetched: try: role_id = int(line[1]) except Exception as e: logger("Utils::is_banned", f"{type(e).__name__} - {e}") return True if has_role(role_id, member): try: until = int(line[0]) except Exception as e: logger("Utils::is_banned", f"{type(e).__name__} - {e}") return True if until > math.floor(time.time()): # still ban return True # neither return False
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 send_token(self, ctx, member: discord.Member = None): """Send the token's link in a DM""" member = member or ctx.author guild_id = ctx.guild.id error = False try: colour = discord.Colour(0) url = Utils.get_text( guild_id, 'gallery_token') + await self.get_galerie_link( guild_id, member) sql = f"select message from galerie_message where guild_id='{guild_id}'" galerie_message = database.fetch_one_line(sql) if galerie_message: url = url + "\n\n" + galerie_message[0] colour = colour.from_rgb(170, 117, 79) icon_url = "https://cdn.discordapp.com/attachments/494812564086194177/597037745344348172/LotusBlanc.png" name = self.bot.user.display_name embed = discord.Embed(colour=colour) embed.set_author(icon_url=icon_url, name=name) embed.description = url embed.timestamp = datetime.utcnow() await member.send(content=None, embed=embed) await ctx.message.add_reaction('✅') except Exception as e: await ctx.message.channel.send( Utils.get_text(ctx.guild.id, 'error_user_disabled_PM').format( member.display_name)) logger("gallery::send_token", f" {type(e).__name__} - {e}") await ctx.message.add_reaction('❌') error = True await self.logger.log('galerie_log', ctx.author, ctx.message, 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 invite(self, ctx, member: discord.Member = None): """Send the invitation's link in a DM""" member = member or ctx.author guild_id = ctx.guild.id error = False colour = discord.Colour(0) try: url = "Votre lien d'invitation:\n" + await self.get_invitation_link( guild_id) sql = f"select message from invite_message where guild_id='{guild_id}'" invite_message = database.fetch_one_line(sql) if invite_message: url = url + "\n" + invite_message[0] colour = colour.from_rgb(255, 51, 124) icon_url = "https://cdn.discordapp.com/attachments/597091535242395649/597091654847037514/Plan_de_travail_18x.png" name = "Steven Universe Fantasy" embed = discord.Embed(colour=colour) embed.set_author(icon_url=icon_url, name=name) embed.description = url embed.timestamp = datetime.utcnow() await member.send(content=None, embed=embed) await ctx.message.add_reaction('✅') except Exception as e: await ctx.message.channel.send( Utils.get_text(ctx.guild.id, "error_user_disabled_PM").format( member.display_name)) print(f"{type(e).__name__} - {e}") await ctx.message.add_reaction('❌') error = True await self.logger.log('invite_log', ctx.author, ctx.message, error)
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 list_cogs_guild(self, ctx): """ Command which lists all loaded cogs for this guild """ author = ctx.author guild_id = ctx.guild.id all_loaded = "" for name in self.bot.cogs.keys(): cog = name.lower() try: select = ("select status " "from config_cog " + "where " + "cog=? " + " and " + "guild_id=? ;" + "") fetched = database.fetch_one_line(select, [cog, guild_id]) if (fetched and fetched[0] == 1) or (cog in [ "configuration", "help", "loader", "logs" ]): all_loaded += f"- **{name}**\n" except Exception as e: logger("loader::list_cogs_guild", f"{type(e).__name__} - {e}") if not len(all_loaded): all_loaded = "**NONE**" try: await ctx.send(all_loaded) except Exception as e: logger("loader::list_cogs_guild", f'{type(e).__name__} - {e}')
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_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_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))
def embed_get_no_result(self, message_id, guild_id, embed): # valid message saved ? sql = f"select channel_id,closed,month,year from vote_message where message_id='{message_id}' and guild_id='{guild_id}'" fetched = database.fetch_one_line(sql) if not fetched: logger ("vote::embed_get_no_result", "impossibru") return # vote closure status channel_id = int(fetched[0]) end_proposition = (fetched[1] == 1) end_edit = (fetched[1] == 2) vote_closed = (fetched[1] == 3) month = fetched[2] year = fetched[3] field = embed.fields[0] select = f"select proposition_id,emoji,proposition,ballot from vote_propositions where message_id='{message_id}' order by proposition_id asc ;" fetched = database.fetch_all_line(select) if not fetched: new_value = "\uFEFF" else: for line in fetched: proposition_id = line[0] emoji = line[1] proposition = line[2] ballot = line[3] if proposition_id == 1: new_value = "- " + emoji + " " + proposition else: new_value = new_value + "\n - " + emoji + " " + proposition field = embed.fields[0] embed.clear_fields() embed.add_field(name=field.name, value=new_value, inline=False) return embed
async def next_nickname(self, ctx): member = ctx.author guild_id = ctx.guild.id nickname_delay = Utils.nickname_delay(guild_id) or botconfig.config[ str(guild_id)]['nickname_cannot_change'] sql = f'select last_change from last_nickname where guild_id=\'{guild_id}\' and member_id=\'{member.id}\'' fetched = database.fetch_one_line(sql) error = False if fetched: last_timestamp = time.mktime( datetime.strptime(fetched[0], "%Y-%m-%d %H:%M:%S").timetuple()) if str(nickname_delay).isnumeric(): nickname_delay = int(nickname_delay) else: nickname_delay = Utils.convert_str_to_time(nickname_delay) duree = math.floor((last_timestamp + nickname_delay) - time.time()) if duree > 0: await ctx.send(Utils.get_text(guild_id, "nickname_cannot_change").format( Utils.format_time(duree)), delete_after=5.0) error = True if not error: self._add_next_timer(member.id, guild_id) try: await ctx.send(Utils.get_text(guild_id, "nickname_can_change"), delete_after=5.0) except discord.Forbidden: await ctx.send(Utils.get_text(guild_id, "error_user_disabled_PM_2"), delete_after=5.0) await ctx.message.delete(delay=5.0) await self.logger.log('nickname_log', member, ctx.message, error)
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 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))
def is_already_warned_messages(self, message_id, emoji, guild_id): # cursor.execute('CREATE TABLE IF NOT EXISTS `rules_message` (`message_id` TEXT NOT NULL, `emoji_text` VARCHAR(64) NOT NULL, `guild_id` VARCHAR(256) NOT NULL, PRIMARY KEY (`message_id`, `emoji_text`, `guild_id`)) ;') select = ("select emoji_text " + " from rules_message " + " where " + " message_id=? " + " and " + " emoji_text=? " + " and " + " guild_id=? " + "") fetched = database.fetch_one_line(select, [message_id, emoji, guild_id]) return (fetched and fetched[0])
def is_correct_emoji(self, message_id, guild_id, emoji): # check if message = vote select = f"select ballot from vote_propositions where message_id='{message_id}' and guild_id='{guild_id}' and emoji='{emoji}' ;" fetched = database.fetch_one_line(select) if not fetched: logger ("vote::is_correct_emoji", f"Invalid emoji: {emoji} on message {message_id} in {guild_id}") return False return True
async def timerset(self, ctx: commands.Context): """ """ guild_id = ctx.guild.id if ctx.invoked_subcommand is None: # display config # GET EMOJI select = "select emoji from timer_emoji where guild_id=? ;" fetched = database.fetch_one_line(select, [guild_id]) if not fetched: emoji = Utils.emojize(":red_circle:") else: emoji = await Utils.get_emoji(ctx, fetched[0]) # GET END MESSAGE select = "select end_message from timer_end_message where guild_id=? ;" fetched = database.fetch_one_line(select, [guild_id]) if not fetched: end_message = "**Time's Up !**" else: end_message = fetched[0] # GET DO FIRST EMOJI select = "select do from config_do where type_do=? and guild_id=? ;" fetched = database.fetch_one_line(select, ["first_emoji", guild_id]) if not fetched: do_first_emoji = False else: do_first_emoji = fetched[0] # GET FIRST EMOJI select = "select emoji from timer_first_emoji where guild_id=? ;" fetched = database.fetch_one_line(select, [guild_id]) if not fetched: first_emoji = Utils.emojize(":green_circle:") else: first_emoji = await Utils.get_emoji(ctx, fetched[0]) message_to_send = (">>> " "Emoji: {0}\n" "End Message: {1}\n" "First Emoji: {2}\n" "Do First Emoji: {3}\n").format( emoji, end_message, first_emoji, Utils.str_bool(do_first_emoji)) await ctx.send(message_to_send) return
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])