Ejemplo n.º 1
0
    async def get_settings(self, ctx):
        """
		prints set channels
		"""
        db = sqltils.DbConn(db_file, ctx.guild.id, "setting")
        results = db.read_server_table()  #gets a list ob entry objects

        pub = "__Public Channels:__\n"
        priv = "__Private Channels:___\n"
        log = "__Log Channel__\n"
        archive = "__Archive Category__\n"
        for i in range(len(results)):  #building strings
            if results[i].setting == "pub-channel":
                pub += f"`{ctx.guild.get_channel(results[i].value_id)}` with ID `{results[i].value_id}`\n"

            elif results[i].setting == "priv-channel":
                priv += f"`{ctx.guild.get_channel(results[i].value_id)}` with ID `{results[i].value_id}`\n"

            elif results[i].setting == "log":
                log += f"`{ctx.guild.get_channel(results[i].value_id)}` with ID `{results[i].value_id}`\n"

            elif results[i].setting == "archive":
                archive += f"`{ctx.guild.get_channel(results[i].value_id)}` with ID `{results[i].value_id}`\n"

        emby = utils.make_embed(color=discord.Color.green(),
                                name="Server Settings",
                                value=f"‌\n{pub}\n {priv}\n{archive}\n{log}")
        await ctx.send(embed=emby)
Ejemplo n.º 2
0
    async def edit_channel(self, ctx, value: str):
        settings = {'yes': 1, 'no': 0}

        value_num = settings.get(value.lower())
        if value_num != None:
            db = sqltils.DbConn(db_file, ctx.guild.id, "setting")

            # if setting is already there old value needs to be deleted
            if len(db.search_table(value="edit_channel", column="setting")
                   ) == 1:  # there can only be one archive and log
                db.remove_line('"edit_channel"', column="setting")

            entry = ("edit_channel", "value_name", value_num,
                     time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL)
            db.write_server_table(entry)

            emby = utils.make_embed(
                color=discord.Color.green(),
                name="Success",
                value=f"Channel Creator can edit channel-name: {value}")
            await ctx.send(embed=emby)

        else:
            emby = utils.make_embed(
                color=discord.Color.orange(),
                name="Missing argument",
                value=f"Please enter `yes` or `no` as argument.")
            await ctx.send(embed=emby)
Ejemplo n.º 3
0
    async def set_archive(self, ctx, setting: str, value: str):
        # possible settings switch -returns same value but nothing if key isn't valid
        settings = {
            "archive": utils.get_chan(ctx.guild, value),
            "log": utils.get_chan(ctx.guild, value)
        }
        # trying to get a corresponding channel / id
        value = settings.get(setting)
        # if value is "None" this means that there is no such setting or no such value for it
        # checking if keyword matches the entered channel type
        # -> ensures that the process of getting a correct setting has worked

        # set channels
        if value is not None and value.type == discord.ChannelType.text and setting == "log" \
                or value.type == discord.ChannelType.category and setting == "archive":

            # connecting to db - creating a new one if there is none yet
            db = sqltils.DbConn(db_file, ctx.guild.id, "setting")

            # Settings won't be stored if max watched channels are reached
            # -> searching for amount of matching entries
            if len(db.search_table(value=setting, column="setting")
                   ) >= 1:  # there can only be one archive and log

                text = f"Hey, you can only have one archive and log at once\n \
                        If you wanna change those settings use `{config.PREFIX}ds [channel-id]` to remove a channel from your settings"

                emby = utils.make_embed(color=discord.Color.orange(),
                                        name="Too many entries",
                                        value=text)
                await ctx.send(embed=emby)

            # writing entry to db - the way things should go
            else:
                entry = (setting, "value_name", value.id,
                         time.strftime("%Y-%m-%d %H:%M:%S"),
                         config.VERSION_SQL)
                db.write_server_table(entry)

                emby = utils.make_embed(color=discord.Color.green(),
                                        name="Success",
                                        value="Setting saved")
                await ctx.send(embed=emby)

        # when false inputs were given
        else:
            value = ("Please ensure that you've entered a valid setting \
                    and channel-id or role-id for that setting.")
            emby = utils.make_embed(color=discord.Color.orange(),
                                    name="Can't get setting",
                                    value=value)
            await ctx.send(embed=emby)
Ejemplo n.º 4
0
async def make_channel(
        voice_state: discord.VoiceState,
        member: discord.Member,
        voice_overwrites: discord.PermissionOverwrite,
        vc_name="voice-channel",
        tc_name="text-channel",
        channel_type="pub"
) -> Tuple[discord.TextChannel, discord.VoiceChannel]:
    """
    Method to create a voice-channel with linked text-channel logging to DB included\n
    -> VCs created with this method are meant to be deleted later on, therefore they're logged to DB

    :param voice_state: To detect which VC the member is in
    :param member: To access guild and give member TC access permissions
    :param voice_overwrites: To give member extra permissions in the VC and TC
    :param vc_name: Voice Channel name
    :param tc_name: Text Channel name
    :param channel_type: For SQL-logging can be "pub" or "priv"

    :returns: Created Text and VoiceChannel Objects
    """
    # creating channels
    v_channel = await member.guild.create_voice_channel(
        vc_name,
        category=voice_state.channel.category,
        overwrites=voice_overwrites)

    t_channel = await member.guild.create_text_channel(
        tc_name,
        category=voice_state.channel.category,
        overwrites={
            member:
            discord.PermissionOverwrite(view_channel=True),
            member.guild.default_role:
            discord.PermissionOverwrite(view_channel=False)
        })

    # writing new channels to db
    db = sqltils.DbConn(db_file, member.guild.id, "created_channels")

    db.write_server_table(
        (channel_type, v_channel.id, t_channel.id,
         time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))

    return v_channel, t_channel
    async def close_rooms(self, ctx: commands.Context):
        # check if member is not in voice
        if not ctx.author.voice:
            await hp.send_embed(ctx, embed=utils.make_embed("You're not in a VoiceChannel", discord.Color.orange(),
                                                            value="Please enter a Voice Channel and try again"))
            return

        # getting break-out rooms from database
        db = sqltils.DbConn(config.DB_NAME, ctx.guild.id, "created_channels")
        breakout_rooms: List[sqltils.SQL_to_Obj] = db.search_table(value='"brout"', column="type")

        # iterating trough break out rooms, moving members back in main channel
        # deletion of channels will be handled in separate on_voice_channel_update event when channel is empty
        back_channel = ctx.author.voice.channel
        for room in breakout_rooms:
            ch: discord.VoiceChannel = ctx.guild.get_channel(room.channel)
            if ch is None:  # channel already deleted
                continue
            for m in ch.members:
                if m.voice is None:  # member left voice chat
                    continue
                await m.move_to(back_channel)
Ejemplo n.º 6
0
    async def delete_settings(self, ctx, value):
        """
        remove set channels
        """
        if value:
            db = sqltils.DbConn(db_file, ctx.guild.id, "setting")
            try:
                int(value)  # fails when string is given
                if len(value) == 18:
                    # all checks passed - removing that entry
                    db.remove_line(int(value), column="value_id")
                    channel = ctx.guild.get_channel(int(value))
                    await ctx.send(embed=utils.make_embed(
                        color=discord.Color.green(),
                        name="Deleted",
                        value=f"Removed `{channel}` from settings"))
                else:
                    raise  # enter except

            except:
                emby = utils.make_embed(color=discord.Color.orange(),
                                        name="No valid channel ID",
                                        value="It seems like you din't \
                                    give me a valid channel ID to work with")
                await ctx.send(embed=emby)
            # db.remove_line(value, column="value")

        else:
            emby = utils.make_embed(
                color=discord.Color.orange(),
                name="No input",
                value=f"This function requires exactly one input:\n \
                                `channel-ID` please give a valid channel ID as argument to remove that channel from \
                                the list of watched channels.\n \
                                You can get a list of all watched channels with `{config.PREFIX}gs`"
            )

            await ctx.send(embed=emby)
Ejemplo n.º 7
0
    async def setup_voice(self, ctx, role=None):
        await ctx.trigger_typing()
        ov = {
            ctx.guild.default_role:
            discord.PermissionOverwrite(view_channel=True,
                                        connect=True,
                                        speak=True)
        }

        if role:  #if there was a role as input - making custom overwrite
            role, leng = utils.get_rid(ctx, [role])
            role = ctx.guild.get_role(role[0])
            print(role)
            if role:
                ov = {
                    ctx.guild.default_role:
                    discord.PermissionOverwrite(view_channel=False,
                                                connect=False,
                                                speak=False),
                    role:
                    discord.PermissiosnOverwrite(view_channel=True,
                                                 connect=True,
                                                 speak=True)
                }
            else:
                await ctx.send(embed=utils.make_embed(value="Hey, the given id is invalid,\
								I'm trying to create the channels but with the default settings."                                                                                     ,\
                    name="No valid role", color=discord.Color.orange()))
        #creating channels
        cat = await ctx.guild.create_category_channel(
            "Voice Channels", overwrites=ov, reason="Created voice setup")
        await cat.edit(overwrites=ov,
                       position=0)  #move up didn't work in the creation
        pub_ch = await ctx.guild.create_voice_channel(
            "╔create-voice-channel",
            category=cat,
            reason="Created voice setup")
        priv_ch = await ctx.guild.create_voice_channel(
            "╠new-private-channel", category=cat, reason="Created voice setup")
        db = sqltils.DbConn(db_file, ctx.guild.id, "setting")
        #checking if db has three entries for one of those settings
        if len(db.search_table(value="pub-channel", column="setting")) < config.SET_LIMIT \
        or len(db.search_table(value="priv-channel", column="setting")) < config.SET_LIMIT:
            db.write_server_table(
                ("pub-channel", "value_name", pub_ch.id,
                 time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))
            db.write_server_table(
                ("priv-channel", "value_name", priv_ch.id,
                 time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))

            await ctx.send(embed=utils.make_embed(name="Sucessfully setup voice category",\
               value="You're category is set, have fun!\n \
						Oh, yeah - you can change the channel names how ever you like :)"                                                                                , color=discord.Color.green()))

        else:  #if channel max was reached
            await ctx.send(embed=utils.make_embed(
                name="Too many channels!",
                value=
                f"Hey, you can't make me watch more than {config.SET_LIMIT} channels per creation type.\n\
							If you wanna change the channels I watch use \
							`{config.PREFIX}ds [channel-id]` to remove a channel from your settings\n \
							The channels were created but aren't watched, have a look at `{config.PREFIX}help settings`\
							to add them manually after you removed other watched channels from the settings"
            ))
Ejemplo n.º 8
0
 def del_entry(self, channel):
     db = sqltils.DbConn(db_file, self.member.guild.id, "created_channels")
     db.remove_line(channel, column="channel_id")
Ejemplo n.º 9
0
 def is_created_channel(self, channel: int) -> list:
     #checks if joined channel is a custom created one - returns all results as objects
     db = sqltils.DbConn(db_file, self.member.guild.id, "created_channels")
     return db.search_table(value=channel, column="channel_id")
Ejemplo n.º 10
0
 def __init__(self, member, before, after):
     self.member = member
     self.before = before
     self.after = after
     self.db = sqltils.DbConn(db_file, self.member.guild.id, "setting")
Ejemplo n.º 11
0
    async def on_voice_state_update(self, member, before, after):
        def make_overwrite(
            members: list
        ) -> dict:  #creates the overwrites dict for the text-channel
            return {
                m: discord.PermissionOverwrite(view_channel=True)
                for m in members
            }

        def update_text_channel(cchannel):
            #function that makes the dict overwrites for text channels
            v_channel = member.guild.get_channel(cchannel[0].channel)
            t_channel = member.guild.get_channel(cchannel[0].linked_channel)
            overwrites = {
                member.guild.default_role:
                discord.PermissionOverwrite(view_channel=False)
            }
            overwrites.update(make_overwrite(v_channel.members))
            return t_channel, overwrites

        #object that performs checks which cases are true
        checker = EventCheck(member, before, after)
        l_channel = checker.get_log()  #log channel

        if after.channel:  #check if person is in channel
            #check if creating is triggered creation type or none
            ch_type = checker.is_activate()
            #if joined channel was created - returns list with objects of all positive results
            cchannel = checker.is_created_channel(after.channel.id)
            #creating channel
            if ch_type:
                channel_name = random.choice(
                    channel_names[ch_type])  #getting channel name

                v_overwrites = {}  #None except it's a private channel
                if ch_type == "priv":  #giving member special perms when private channel
                    v_overwrites = {
                        member:
                        discord.PermissionOverwrite(
                            manage_permissions=True,
                            manage_channels=True,
                            connect=True
                        ),  #give member connect and manage rights 
                        member.guild.default_role:
                        discord.PermissionOverwrite(connect=False)
                    }

                #creating channels
                v_channel = await member.guild.create_voice_channel(
                    channel_name[0].format(member.display_name),
                    category=after.channel.category,
                    overwrites=v_overwrites)
                t_channel = await member.guild.create_text_channel(
                    channel_name[1].format(member.display_name),
                    category=after.channel.category,
                    overwrites={
                        member:
                        discord.PermissionOverwrite(view_channel=True),
                        member.guild.default_role:
                        discord.PermissionOverwrite(view_channel=False)
                    })

                #writing new channels to db
                db = sqltils.DbConn(db_file, member.guild.id,
                                    "created_channels")
                db.write_server_table(
                    (ch_type, v_channel.id, t_channel.id,
                     time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))

                if l_channel:
                    await l_channel.send(embed=utils.make_embed(
                        name="Created Voicechannel",
                        value=
                        f"{member.mention} created `{v_channel}` with {t_channel.mention}",
                        color=discord.Color.green()))

                #moving creator to his channel
                await member.move_to(v_channel,
                                     reason=f'{member} issued creation')

            elif cchannel:  #adding member to textchannel, if member joined created channel
                t_channel, overwrites = update_text_channel(cchannel)
                await t_channel.edit(overwrites=overwrites)

        if before.channel:  #if member leaves channel
            cchannel = checker.is_created_channel(before.channel.id)

            if before.channel.members == [] and cchannel:  #if channel is empty -> delete
                v_channel = member.guild.get_channel(cchannel[0].channel)
                t_channel = member.guild.get_channel(
                    cchannel[0].linked_channel)
                #check if archive is given and if channel contains messages to archive
                try:  #trying to archive category - throws an error when category is full
                    if (checker.get_archive()
                        ) and t_channel.last_message != None:
                        archive = checker.get_archive()
                        await t_channel.edit(
                            category=archive,
                            reason="Voice is empty, this channel not")

                    else:  #empty channel
                        await t_channel.delete(
                            reason="Channel is empty and not needed anymore")

                    checker.del_entry(v_channel.id)  #removing entry from db
                    await v_channel.delete(reason="Channel is empty")
                    if l_channel:  #logging
                        await l_channel.send(embed=utils.make_embed(
                            name="Created Voicechannel",
                            value=
                            f"{member.mention} created `{v_channel}` with {t_channel.mention}",
                            color=discord.Color.green()))

                #happens when if archive is full
                except discord.errors.HTTPException:
                    await l_channel.send(embed=utils.make_embed(
                        name="ERROR",
                        color=discord.Color.red(),
                        value=
                        f"This error probably means that the archive category is full, please check it and \n \
										set a new one or delete older channels - Nothing was deleted"))

            elif cchannel:  #removing member from textchannel when left
                t_channel = member.guild.get_channel(
                    cchannel[0].linked_channel)
                t_channel, overwrites = update_text_channel(cchannel)
                await t_channel.edit(overwrites=overwrites)