Exemplo n.º 1
0
    async def create(self, ctx):
        check = await self.check_in_role(ctx)
        if check == 2 or check == 0:
            i = await self.create_voice(ctx)
            if i:
                new_channel = i.get("new_channel")
                embed_var = discord.Embed(title="vc create",
                                          description=f"""
                                        Name: {str(new_channel)}
                                        Speaker: {i.get("mention_name")}
                                        Creator: {ctx.author.mention}
        
                                        Started: {time_zone_time(ctx)}
                                        """,
                                          color=self.start_colour)
                response_msg = await ctx.channel.send(embed=embed_var)

                db.save_channel(ctx.guild.id, new_channel.id, None,
                                ctx.channel.id, response_msg.id, 1, 0)

                logger.info("(create) used")
                db.stats_save(self, ctx, ctx.author, str(ctx.command))

                if ctx.author.voice:
                    await ctx.author.move_to(new_channel)
Exemplo n.º 2
0
async def send_stats(self, ctx):
    embed_var = get_stats(self)
    msg = await ctx.send(embed=embed_var)
    emoji = self.bot.config["refresh_emoji"]
    await msg.add_reaction(emoji)
    db.save_reaction(ctx.guild.id, msg.id, emoji, "stats")
    db.stats_save(self, ctx, ctx.author, str(ctx.command))
Exemplo n.º 3
0
async def permission(self, ctx):
    embed_var = discord.Embed(title="Permission",
                              description=f"""
                These are the permission needed to run me properly. Please enable them.
                """,
                              color=discord.Color.random())
    embed_var.add_field(name="Lists", value=self.config["permissions"])
    await ctx.send(embed=embed_var)
    db.stats_save(self, ctx, ctx.author, str(ctx.command))
Exemplo n.º 4
0
    async def private(self, ctx):
        check = await self.check_in_role(ctx)
        if check == 0:
            i = await self.create_voice(ctx)
            j = await self.create_text(ctx)
            if i and j:
                voice_channel = i.get("new_channel")
                text_channel = j.get("new_channel")

                # set permission
                await voice_channel.set_permissions(self.bot.users[0],
                                                    connect=True)
                await text_channel.set_permissions(self.bot.users[0],
                                                   read_messages=True)
                for q in i.get("mention"):
                    await voice_channel.set_permissions(q, connect=True)
                    await text_channel.set_permissions(q, read_messages=True)
                await voice_channel.set_permissions(ctx.guild.roles[0],
                                                    connect=False)
                await text_channel.set_permissions(ctx.guild.roles[0],
                                                   read_messages=False)

                embed_var = discord.Embed(title="vc private",
                                          description=f"""
                                            Name: {str(voice_channel)}
                                            Speaker + Listener: {i.get("mention_name")}
                                            Creator: {ctx.author.mention}
        
                                            Started: {time_zone_time(ctx)}
                                            """,
                                          color=self.private_colour)
                response_msg = await ctx.channel.send(embed=embed_var)

                db.save_channel(ctx.guild.id, voice_channel.id,
                                text_channel.id, ctx.channel.id,
                                response_msg.id, 1, 1)
                logger.info("(private) used")
                db.stats_save(self, ctx, ctx.author, str(ctx.command))

                if ctx.author.voice:
                    await ctx.author.move_to(voice_channel)

        elif check == 2:
            embed_var = discord.Embed(title="",
                                      description=f"""
                                    {ctx.author.mention}
                                    You need to ping a user to create a private channel, use "vc create" instead 
                                    """,
                                      color=self.error_colour,
                                      delete_after=60)
            await ctx.channel.send(embed=embed_var)
Exemplo n.º 5
0
async def change_log(self, ctx, version: str):
    description = changelog.get(version)
    if description is not None:
        embed_var = discord.Embed(
            title="Change Log",
            description="",
            color=self.bot.config["primary_light_colour"])
        embed_var.add_field(name="v" + version,
                            value=description,
                            inline=False)
        await ctx.send(embed=embed_var)
        db.stats_save(self, ctx, ctx.author, str(ctx.command))
    else:
        embed_var = discord.Embed(title="",
                                  description=f"""
                {ctx.author.mention}
                Unknown version number.
                Usage: vc change_log [version_number]
                """,
                                  color=0xff0f0f)
        await ctx.send(embed=embed_var)
Exemplo n.º 6
0
    async def on_voice_state_update(self, member: discord.Member, before,
                                    after: discord.VoiceState):
        await self.kick_check(member, member.guild.id)

        if after.channel is not None:
            # user join a channel
            result, related_channels = db.get_special_channel(after.channel.id)
            if result:
                if result["type"] == "auto_create":
                    channel_number = related_channels[0][
                        0] + 1 if related_channels[0][0] is not None else 1
                    channel_name = after.channel.name + " " + str(
                        channel_number)
                    if after.channel.category is not None:
                        new_channel = await after.channel.category.create_voice_channel(
                            channel_name)
                    else:
                        new_channel = await after.channel.guild.create_voice_channel(
                            channel_name)
                    db.add_related_channel(member.guild.id,
                                           new_channel.id,
                                           special_channel_id=after.channel.id,
                                           vc_delete=1,
                                           channel_number=channel_number)
                    db.stats_save(self, member, member, "auto_create")
                    await member.move_to(new_channel)

        if before.channel is not None:
            # user leave a voice channel
            result = db.get_channel(before.channel.id)
            if result:
                if result["type"] in ("normal", "study", "gaming"):
                    if not before.channel.members:
                        if result.get("vc_delete") == 1:
                            await before.channel.delete()
                            logger.info("a voice channel is deleted")
                        if result.get("tx_delete") == 1:
                            tx_channel = self.bot.get_channel(
                                result.get("tx_channel_id"))
                            await tx_channel.delete()
                            logger.info("a text channel is deleted")

                        if result["msg_channel_id"] is not None:
                            msg_channel_id = result.get("msg_channel_id")
                            msg_channel = self.bot.get_channel(msg_channel_id)
                            response_msg = await msg_channel.fetch_message(
                                result.get("response_msg_id"))
                            embeds = response_msg.embeds[0]
                            if embeds:
                                embed_var = discord.Embed(
                                    title=f"{embeds.title} (deleted)",
                                    description=f"""
                                                            {embeds.description} 
                                                            Ended: {time_zone_time(before.channel)}
                                                            """,
                                    color=self.end_colour)
                                await response_msg.edit(embed=embed_var)

                        db.delete_channel(before.channel.id)

                        db.stats_save(self, member, str(member), "vc_deleted")
Exemplo n.º 7
0
    async def text(self, ctx):
        check = await self.check_in_role(ctx)
        if check == 2 or check == 0:
            if ctx.author.voice is not None:
                # User in a voice channel
                i = db.get_channel(ctx.author.voice.channel.id)
                if i is not None:
                    # User in a voice channel created by Vcc
                    if i.get("tx_channel_id") is None:
                        # User's channel does NOT has a text channel
                        text_channel = await self.create_text(ctx)
                        if text_channel:
                            msg_channel = self.bot.get_channel(
                                i.get("msg_channel_id"))
                            response_msg = await msg_channel.fetch_message(
                                i.get("response_msg_id"))
                            embeds = response_msg.embeds[0]
                            if embeds:
                                description = embeds.description.split("\n")
                                description.insert(
                                    1,
                                    f"Text: {str(text_channel.get('new_channel'))}"
                                )
                                embed_var = discord.Embed(
                                    title="vc text",
                                    description="\n".join(map(
                                        str, description)),
                                    color=self.start_colour)
                                await response_msg.edit(embed=embed_var)
                            db.update_channel(
                                text_channel.get("new_channel").id,
                                ctx.author.voice.channel.id)
                    else:
                        # User's channel has a text channel
                        i = await self.create_voice(ctx)
                        q = await self.create_text(ctx)
                        if i and q:
                            voice_channel = i.get("new_channel")
                            embed_var = discord.Embed(title="vc text",
                                                      description=f"""
                                                                    Name: {str(voice_channel)}
                                                                    Speaker: {q.get("mention_name")}
                                                                    Creator: {ctx.author.mention}
    
                                                                    Started: {time_zone_time(ctx)}
                                                                    """,
                                                      color=self.start_colour)
                            response_msg = await ctx.channel.send(
                                embed=embed_var)
                            db.save_channel(ctx.guild.id, voice_channel.id,
                                            q.get("new_channel").id,
                                            ctx.channel.id, response_msg.id, 1,
                                            1)

                            if ctx.author.voice:
                                await ctx.author.move_to(voice_channel)
                else:
                    # User in a voice channel NOT created by Vcc
                    q = await self.create_text(ctx)
                    if q:
                        tx_channel = q.get("new_channel")
                        embed_var = discord.Embed(title="vc text",
                                                  description=f"""
                                                        Name: {str(tx_channel)}
                                                        Speaker: {q.get("mention_name")}
                                                        Creator: {ctx.author.mention}

                                                        Started: {time_zone_time(ctx)}
                                                        """,
                                                  color=self.start_colour)
                        response_msg = await ctx.channel.send(embed=embed_var)
                        db.save_channel(ctx.guild.id,
                                        ctx.author.voice.channel.id,
                                        tx_channel.id, ctx.channel.id,
                                        response_msg.id, 0, 1)

            else:
                # User not in a voice channel
                i = await self.create_voice(ctx)
                q = await self.create_text(ctx)
                if i and q:
                    vc_channel = i.get("new_channel")
                    tx_channel = q.get("new_channel")
                    embed_var = discord.Embed(title="vc text",
                                              description=f"""
                                                    Name: {str(vc_channel)}
                                                    Speaker: {i.get("mention_name")}
                                                    Creator: {ctx.author.mention}

                                                    Started: {time_zone_time(ctx)}
                                                    """,
                                              color=self.start_colour)
                    response_msg = await ctx.channel.send(embed=embed_var)
                    db.save_channel(ctx.guild.id, vc_channel.id, tx_channel.id,
                                    ctx.channel.id, response_msg.id, 1, 1)

                    if ctx.author.voice:
                        await ctx.author.move_to(vc_channel)

            logger.info("(text) used")
            db.stats_save(self, ctx, ctx.author, "text")