コード例 #1
0
    async def set_name(self, ctx, *, name: str):
        """Set new display name"""
        if not repo_u.exists(ctx.author.id):
            return await ctx.author.send(f"Register with `{self.p}register`")
        if repo_u.get_attribute(ctx.author.id, "restricted") == 1:
            return await ctx.author.send("You are forbidden to alter your settings.")
        name = self.sanitise(name, limit=32)
        u = repo_u.get_by_nickname(name)
        if u is not None:
            return await ctx.author.send("This name is already used by someone.")
        # fmt: off
        disallowed = (
            "(", ")", "*", "/", "@", "\\", "_", "`",
            "\u200B", "\u200C", "\u200D", "\u2028", "\u2060", "\uFEFF",
            # guild emojis
            "<:", "<a:",
        )
        # fmt: on
        for char in disallowed:
            if char in name:
                return await ctx.author.send("The name contains forbidden characters.")

        before = repo_u.get_attribute(ctx.author.id, "nickname")
        repo_u.set(ctx.author.id, key="nickname", value=name)
        await ctx.author.send(f"Your nickname was changed to **{name}**")
        await self.event.user(ctx, f"Nickname changed from **{before}** to **{name}**.")
コード例 #2
0
    async def register(self, ctx):
        """Add yourself to the database"""
        if repo_u.exists(ctx.author.id):
            return await ctx.author.send("You are already registered.")

        nickname = self.sanitise(ctx.author.name, limit=12).replace(")", "").replace("(", "")

        # get first available nickname
        i = 0
        name_orig = nickname
        while repo_u.is_nickname_used(nickname):
            nickname = f"{name_orig}{i}"
            i += 1

        # register
        repo_u.add(discord_id=ctx.author.id, nickname=nickname)
        if isinstance(ctx.channel, discord.TextChannel) and repo_w.get(ctx.channel.id):
            beam_name = repo_w.get(ctx.channel.id).beam
            repo_u.set(ctx.author.id, key=f"home_id:{beam_name}", value=ctx.channel.id)

        await self.event.user(ctx, f"Registered as **{nickname}**.")
        await ctx.author.send(
            f"You are now registered as `{nickname}`. "
            f"You can display your information with `{self.p}me`.\n"
            f"To see information about another user, enter `{self.p}whois [nickname]`.\n\n"
            f"You can tag other registered users with `((nickname))`."
        )
コード例 #3
0
    async def user_edit(self, ctx, member: discord.Member, key: str,
                        value: str):
        """Edit user"""
        if (ctx.author.id != config["admin id"]
                and repo_u.get_attribute(member.id, "mod") == 1):
            return await ctx.send(
                "> You do not have permission to alter mod accounts")
        if ctx.author.id != config["admin id"] and member.id == config[
                "admin id"]:
            return await ctx.send(
                "> You do not have permission to alter admin account")

        if key in ("mod", "readonly", "restricted"):
            try:
                value = int(value)
            except ValueError:
                raise errors.BadArgument("Value has to be integer.")
        elif key.startswith("home_id:"):
            try:
                value = int(value)
            except ValueError:
                raise errors.BadArgument("Value has to be integer.")

        repo_u.set(discord_id=member.id, key=key, value=value)
        await self.event.sudo(ctx, f"{member.id} updated: {key} = {value}.")
コード例 #4
0
ファイル: admin.py プロジェクト: sinus-x/discord-wormhole
    async def block(self, ctx, member: discord.Member):
        """Block discord user from sending messages"""
        nickname = self.sanitise(member.name,
                                 limit=16).replace(")", "").replace("(", "")
        nickname = self.get_free_nickname(nickname)

        if not repo_u.exists(discord_id=member.id):
            self.user_add(ctx, member_id=member.id, nickname=nickname)

        repo_u.set(discord_id=member.id, key="readonly", value=1)
        await self.event.sudo(ctx, f"User **{nickname}** blocked.")
コード例 #5
0
    async def set_home(self, ctx):
        """Set current channel as your home wormhole"""
        if not repo_u.exists(ctx.author.id):
            return await ctx.author.send(f"Register with `{self.p}register`")
        if repo_u.get_attribute(ctx.author.id, "restricted") == 1:
            return await ctx.author.send("You are forbidden to alter your settings.")
        if not isinstance(ctx.channel, discord.TextChannel) or not repo_w.exists(ctx.channel.id):
            return await ctx.author.send("Home has to be a wormhole")

        beam_name = repo_w.get(ctx.channel.id).beam
        repo_u.set(ctx.author.id, key=f"home_id:{beam_name}", value=ctx.channel.id)
        await ctx.author.send("Home set to " + ctx.channel.mention)
        await self.event.user(
            ctx, f"Home in **{beam_name}** set to **{ctx.channel.id}** ({ctx.guild.name})."
        )