async def add_to_censor_list(self, ctx, *, text: str): if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "automod") is False: return await ctx.send( Translator.translate(ctx.guild, "black_list_disabled", _emote="NO", prefix=ctx.prefix)) _censor_list = [ x for x in DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "censored_words") if x != "--------------" ] if text.lower() in [ x.strip().lower() for x in DBUtils.get( db.configs, "guildId", f"{ctx.guild.id}", "censored_words") if x != "--------------" ]: return await ctx.send( Translator.translate(ctx.guild, "already_on_black_list", _emote="NO", word=text)) _censor_list.append(str(text)) DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "censored_words", _censor_list) await ctx.send( Translator.translate(ctx.guild, "added_to_black_list", _emote="YES", word=text))
async def black_list(self, ctx): """black_list_help""" if ctx.invoked_subcommand is None: if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "automod") is False: return await ctx.send( Translator.translate(ctx.guild, "black_list_disabled", _emote="NO", prefix=ctx.prefix)) _censor_list = [ x.strip().lower() for x in DBUtils.get( db.configs, "guildId", f"{ctx.guild.id}", "censored_words") if x != "--------------" ] if len(_censor_list) < 1: return ctx.send( Translator.translate(ctx.guild, "black_list_empty", _emote="NO", prefix=ctx.prefix)) await ctx.send( Translator.translate(ctx.guild, "censor_list", guild_name=ctx.guild.name, words=_censor_list))
async def rank(self, ctx, user: discord.Member = None): """rank_help""" if user is None: user = ctx.author if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False: return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO")) try: level_id = f"{ctx.guild.id}-{user.id}" xp = DBUtils.get(db.ranks, "levelId", level_id, "xp") lvl = DBUtils.get(db.ranks, "levelId", level_id, "lvl") needed = 10 if lvl <= 1: needed_xp = needed + 1 return await ctx.send(embed=await self._rank(ctx, user, xp, lvl, needed_xp)) counter = 0 while counter < lvl: counter += 1 needed += 40 if counter >= lvl: break needed_xp = needed + 2 return await ctx.send(embed=await self._rank(ctx, user, xp, lvl, needed_xp)) except Exception: await ctx.send(Translator.translate(ctx.guild, "not_ranked", _emote="NO", user=user))
async def ranks(self, ctx): """ranks_help""" if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False: return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO")) level_roles = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "level_roles") if len(level_roles) < 1: return await ctx.send(Translator.translate(ctx.guild, "no_lvl_roles", _emote="NO")) embed = discord.Embed( color=discord.Color.blurple(), title="{} {}".format(ctx.guild.name, Translator.translate(ctx.guild, "lvl_roles")), ) embed.set_thumbnail( url=ctx.guild.icon_url ) for r in level_roles: lvl = r.split("-")[0] _id = r.split("-")[1] if not str(_id) in [str(x.id) for x in ctx.guild.roles]: role = Translator.translate(ctx.guild, "deleted_role") else: role = "<@&{}>".format(_id) embed.add_field( name="**Level {}**".format(lvl), value="{}".format(role), inline=False ) await ctx.send(embed=embed)
async def generate_help_pages(ctx, bot): pages = [] out = [] valid_cogs = [ c for c in bot.cogs if not str(c) in ["Admin", "AntiSpam", "Censor", "GlobalListeners"] ] for cog in valid_cogs: commands = [ " {}{}{}".format(x.name, " " * abs(18 - len(x.name)), Translator.translate(ctx.guild, x.short_doc)) for x in bot.get_cog(cog).get_commands() if x.hidden is False ] output = f"[ {cog} ]\n" + "\n".join(commands) + "\n" out.append(output) for page in Pages.paginate("{}".format("\n".join(out)), prefix="```ini\n", suffix=Translator.translate( ctx.guild, "help_suffix", prefix=DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "prefix"))): pages.append(page) return pages
async def show(self, ctx): """show_help""" try: enabled_modules, disabled_modules = DBUtils.get_module_config( ctx.guild.id) general, messages, members = DBUtils.get_log_channels(ctx.guild.id) e = discord.Embed(color=discord.Color.blurple(), title="Configuration for {}".format( ctx.guild.name)) e.set_thumbnail(url=ctx.guild.icon_url) e.add_field(name=Translator.translate(ctx.guild, "log_channels"), value=Translator.translate(ctx.guild, "log_actions", general=general, messages=messages, members=members), inline=False) e.add_field( name=Translator.translate(ctx.guild, "enabled_modules"), value=", ".join( enabled_modules if len(enabled_modules) > 0 else ["None"]), inline=False) e.add_field( name=Translator.translate(ctx.guild, "disabled_modules"), value=", ".join(disabled_modules if len(disabled_modules) > 0 else ["None"]), inline=False) await ctx.send(embed=e) except Exception: pass
def to_seconds(self, ctx): if self.unit is None: self.unit = "seconds" unit = self.unit.lower() length = self.length if len(unit) > 1 and unit[-1:] == 's': # plural -> singular unit = unit[:-1] if unit == 'w' or unit == 'week': length = length * 7 unit = 'd' if unit == 'd' or unit == 'day': length = length * 24 unit = 'h' if unit == 'h' or unit == 'hour': length = length * 60 unit = 'm' if unit == 'm' or unit == 'minute': length = length * 60 unit = 's' if unit != 's' and unit != 'second': raise PostParseError('length', Translator.translate(ctx.guild, "invalid_lenth_unit")) max_length = 60 * 60 * 24 * 365 if length > max_length: raise PostParseError('length', Translator.translate(ctx.guild, "mex_lenth", max_length=max_langth)) else: return length
async def welcome_msg(self, ctx, *, msg: str): """welcome_msg_help""" if len(msg) > 1500: return await ctx.send( Translator.translate(ctx.guild, "msg_too_long")) DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "welcomeMessage", f"{msg}") await ctx.send( Translator.translate(ctx.guild, "msg_success", _emote="YES"))
async def on_message_delete(self, message: Message): await asyncio.sleep( 1 ) # sleep a bit, we don't log message deletions from the censor module if message.id in self.bot.running_msg_deletions: self.bot.running_msg_deletions.remove(message.id) return c = message.channel channel_id = c.id if isinstance(c, DMChannel): return if c is None or str(channel_id) == str( DBUtils.get( db.configs, "guildId", f"{c.guild.id}", "memberLogChannel")) or not isinstance(c, TextChannel): return if message.author.id == self.bot.user.id: return if c.guild is None: return if DBUtils.get(db.configs, "guildId", f"{c.guild.id}", "messageLogging") is False: return ignored_users = DBUtils.get(db.configs, "guildId", f"{c.guild.id}", "ignored_users") if ignored_users is None: on_time = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") await Logging.log_to_guild( c.guild.id, "messageLogChannel", Translator.translate(message.guild, "log_message_deletion", _emote="BIN", user=message.author, user_id=message.author.id, channel=c.mention, on_time=on_time, content=message.content)) else: if message.author.id in ignored_users: return else: on_time = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") await Logging.log_to_guild( c.guild.id, "messageLogChannel", Translator.translate(message.guild, "log_message_deletion", _emote="BIN", user=message.author, user_id=message.author.id, channel=c.mention, on_time=on_time, content=message.content))
async def command(self, ctx): """commands_help""" if ctx.invoked_subcommand is None: custom_commands = ["{}{}".format(ctx.prefix, x["cmdId"].split("-")[1]) for x in db.commands.find() if x["cmdId"].split("-")[0] == str(ctx.guild.id)] if len(custom_commands) == 0: await ctx.send(Translator.translate(ctx.guild, "no_custom_commands")) else: e = discord.Embed( color=discord.Color.blurple(), title=Translator.translate(ctx.guild, "custom_commands", guild_name=ctx.guild.name), description="\n".join(custom_commands) ) e.set_thumbnail(url=ctx.guild.icon_url) await ctx.send(embed=e)
async def handle_spam(self, guild, member, msg): if DBUtils.get(db.configs, "guildId", f"{guild.id}", "antispam") is False: return # anti spam isn't enabled for this guild c = self.spam_checker[guild.id] if not c.is_spamming(msg): return self.handling.append(member.id) try: await guild.kick(user=member, reason="[AutoMod] Spam") except discord.HTTPException: log.info(f"[Anti Spam] Error while trying to kick {member} ({member.id}) from server {guild} via the anti spam system") else: log.info(f"[Anti Spam] Kicked {member} ({member.id}) from server {guild} via the anti spam system") case = DBUtils.new_case() timestamp = datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M") mod = discord.utils.get(guild.members, id=self.bot.user.id) DBUtils.insert(db.inf, new_infraction(case, msg.guild.id, member, mod, timestamp, "Kick", "[AutoMod] Spam")) on_time = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") await Logging.log_to_guild(guild.id, "memberLogChannel", Translator.translate(guild, "log_spam", _emote="SHOE", on_time=on_time, user=member, user_id=member.id, moderator=self.bot.user, moderator_id=self.bot.user.id, channel=msg.channel.mention)) finally: self.handling.remove(member.id)
async def on_member_remove(self, member: Member): await asyncio.sleep( 1) # sleep a bit, so we don't log an unban made with the bot if member.id in self.bot.running_removals: self.bot.running_removals.remove(member.id) return if DBUtils.get(db.configs, "guildId", f"{member.guild.id}", "memberLogging") is True: joined = (datetime.fromtimestamp(time.time()) - member.joined_at).days try: on_time = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") await Logging.log_to_guild( member.guild.id, "joinLogChannel", Translator.translate(member.guild, "log_leave", _emote="LEAVE", user=member, user_id=member.id, on_time=on_time, joined=joined)) except Exception: pass else: return
async def convert(self, ctx, argument): if argument is None: argument = "seconds" if argument.lower() not in ["week", "weeks", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds", "w", "d", "h", "m", "s"]: raise BadArgument(Translator.translate(ctx.guild, "advanced_invalid_length_unit")) return argument
async def welcome_off(self, ctx): """welcome_off_help""" DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "welcomeChannel", "") DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "welcomeMessage", "") await ctx.send( Translator.translate(ctx.guild, "off_success", _emote="YES"))
async def lvlsystem(self, ctx): DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem", True) await ctx.send( Translator.translate(ctx.guild, "enabled_module_no_channel", _emote="YES", module="rank_system"))
async def _member_logging(self, ctx): DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "memberLogging", False) await ctx.send( Translator.translate(ctx.guild, "disabled_module", _emote="YES", module="join_leave_logging"))
async def _remove(self, ctx, user: discord.User): ignored_users = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "ignored_users") if not user.id in ignored_users: return await ctx.send( Translator.translate(ctx.guild, "not_existing_ignored_user", _emote="NO", user=user.name)) ignored_users.remove(int(user.id)) DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "ignored_users", ignored_users) await ctx.send( Translator.translate(ctx.guild, "ignored_user_removed", _emote="YES", user=user.name))
async def _add(self, ctx, member: discord.Member): ignored_users = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "ignored_users") if member.id in ignored_users: return await ctx.send( Translator.translate(ctx.guild, "already_ignored_user", _emote="YES", user=member.name)) ignored_users.append(int(member.id)) DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "ignored_users", ignored_users) await ctx.send( Translator.translate(ctx.guild, "ignored_user_added", _emote="YES", user=member.name))
async def _lvlsystem(self, ctx): DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem", False) await ctx.send( Translator.translate(ctx.guild, "disabled_module", _emote="YES", module="rank_system"))
async def _automod(self, ctx): DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "automod", False) await ctx.send( Translator.translate(ctx.guild, "disabled_module", _emote="YES", module="automod"))
async def welcome_channel(self, ctx, channel: discord.TextChannel): """welcome_channel_help""" DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "welcomeChannel", channel.id) await ctx.send( Translator.translate(ctx.guild, "channel_success", _emote="YES", channel=channel.mention))
async def action_log(self, ctx, channel: discord.TextChannel): """action_log_help""" DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "memberLogChannel", int(channel.id)) await ctx.send( Translator.translate(ctx.guild, "log_mod_actions", _emote="YES", channel=channel.mention))
async def create(self, ctx, trigger: str, *, reply: str = None): """create_help""" if len(trigger) == 0: await ctx.send(Translator.translate(ctx.guild, "no_trigger", _emote="THINK")) elif reply is None or reply == "": await ctx.send(Translator.translate(ctx.guild, "no_reply", _emote="THINK")) elif len(trigger) > 20: await ctx.send(Translator.translate(ctx.guild, "trigger_too_long")) else: trigger = trigger.lower() if trigger in ["{}".format(x["cmdId"].split("-")[1]) for x in db.commands.find() if x["cmdId"].split("-")[0] == str(ctx.guild.id)]: await ctx.send(Translator.translate(ctx.guild, "command_already_exists")) else: DBUtils.insert(db.commands, Schemas.command_schema(ctx.guild, trigger, reply, ctx.message.author)) try: self.command_cache[str(ctx.guild.id)].append({"trigger": trigger, "reply": reply}) except Exception: self.command_cache[str(ctx.guild.id)] = [{"trigger": trigger, "reply": reply}] finally: await ctx.send(Translator.translate(ctx.guild, "command_added", _emote="YES", command=trigger))
async def member_logging(self, ctx, channel: discord.TextChannel): DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "joinLogChannel", int(channel.id)) DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "memberLogging", True) await ctx.send( Translator.translate(ctx.guild, "enabled_module_channel", _emote="YES", module="join_leave_logging", channel=channel.mention))
async def remove(self, ctx, role: discord.Role): "remove_help" if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False: return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO")) level_roles = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "level_roles") roles = [x.split("-")[1] for x in level_roles] levels = [x.split("-")[0] for x in level_roles] if len(level_roles) < 1: return await ctx.send(Translator.translate(ctx.guild, "no_lvl_roles", _emote="NO")) if not str(role.id) in roles: return await ctx.send(Translator.translate(ctx.guild, "invalid_lvl_role", _emote="NO", role=role)) lvl = levels[roles.index(str(role.id))] level_roles.remove(f"{lvl}-{role.id}") DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "level_roles", level_roles) await ctx.send(Translator.translate(ctx.guild, "removed_lvl_role", _emote="YES", role=role))
async def prefix(self, ctx, new_prefix: str = None): """prefix_help""" if new_prefix is None: await ctx.send( Translator.translate(ctx.guild, "current_prefix", prefix=DBUtils.get( db.configs, "guildId", f"{ctx.guild.id}", "prefix"))) elif len(new_prefix) > 15: await ctx.send( Translator.translate(ctx.guild, "prefix_too_long", _emote="NO")) else: DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "prefix", f"{new_prefix}") await ctx.send( Translator.translate(ctx.guild, "prefix_updated", _emote="YES", prefix=new_prefix))
async def ignored_users(self, ctx): """ignored_users_help""" try: if ctx.invoked_subcommand is None: ignored_users = [] for x in DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "ignored_users"): ignored_users.append(str(x)) if len(ignored_users) < 1: ignored_users.append( Translator.translate(ctx.guild, "no_ignored_users")) e = discord.Embed(color=discord.Color.blurple(), title=Translator.translate( ctx.guild, "ignored_users", guild_name=ctx.guild.name), description="\n".join(ignored_users)) e.set_thumbnail(url=ctx.guild.icon_url) return await ctx.send(embed=e) except Exception: pass
async def add(self, ctx, lvl: RangedInt(2, 200), role: discord.Role): "add_help" if DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "lvlsystem") is False: return await ctx.send(Translator.translate(ctx.guild, "lvlsystem_disabled", _emote="NO")) automod = await Utils.get_member(self.bot, ctx.guild, self.bot.user.id) if role.position >= automod.top_role.position: return await ctx.send(Translator.translate(ctx.guild, "role_too_high")) level_roles = DBUtils.get(db.configs, "guildId", f"{ctx.guild.id}", "level_roles") roles = [x.split("-")[1] for x in level_roles] levels = [x.split("-")[0] for x in level_roles] if str(lvl) in levels: return await ctx.send(Translator.translate(ctx.guild, "already_role_for_lvl", _emote="NO", lvl=lvl)) if str(role.id) is roles: return await ctx.send(Translator.translate(ctx.guild, "already_lvl_role", _emote="NO", role=role)) if len(level_roles) > 10: return await ctx.send(Translator.translate(ctx.guild, "max_lvl_roles", _emote="NO")) level_roles.append(f"{lvl}-{role.id}") DBUtils.update(db.configs, "guildId", f"{ctx.guild.id}", "level_roles", level_roles) await ctx.send(Translator.translate(ctx.guild, "added_lvl_role", _emote="YES", role=role, lvl=lvl))
async def cleanup(self, ctx, search=100): """cleanup_help""" strategy = Utils.basic_cleaning if ctx.me.permissions_in(ctx.channel).manage_messages: strategy = Utils.complex_cleaning deleted = await strategy(ctx, search) await ctx.send( Translator.translate(ctx.guild, "clean_success", _emote="YES", deleted=deleted, plural="" if deleted == 1 else "s"))
async def _level_up(message, lvl_id, user): xp = DBUtils.get(db.levels, "levelId", lvl_id, "xp") lvl = DBUtils.get(db.levels, "levelId", lvl_id, "lvl") # calculations #TODO: It's way to easy to level up, migth have to change that starting_xp = 10 counter = 0 while counter < lvl: counter += 1 if counter > 1: starting_xp += 40 if counter >= lvl: break if lvl > 1: starting_xp += 40 if starting_xp < xp: after = lvl + 1 DBUtils.update(db.levels, "levelId", lvl_id, "lvl", after) try: await message.channel.send(Translator.translate(ctx.guild, "lvl_up", _emote="PARTY", user=user, lvl=after)) except Exception: pass lvl_roles = DBUtils.get(db.configs, "guildId", f"{message.guild.id}", "level_roles") if len(lvl_roles) < 1: return for l in lvl_roles: if str(l.split("-")[0]) == str(after): try: role = discord.utils.get(message.guild.roles, id=int(l.split("-")[1])) await user.add_roles(role) try: await user.send(Translator.translate(ctx.guild, "role_added", user=user.name, role=role.name, guild_name=message.guild.name, lvl=after)) except Exception: pass except Exception: pass