Ejemplo n.º 1
0
async def make_private_room(race_private_info, discord_member):
    # Define permissions
    deny_read = discord.PermissionOverwrite(read_messages=False)
    permit_read = discord.PermissionOverwrite(read_messages=True)

    # Make a channel for the room
    # noinspection PyUnresolvedReferences
    race_channel = await server.client.create_channel(
        server.server,
        get_raceroom_name(race_private_info.race_info),
        discord.ChannelPermissions(target=server.server.default_role, overwrite=deny_read),
        discord.ChannelPermissions(target=server.server.me, overwrite=permit_read),
        discord.ChannelPermissions(target=discord_member, overwrite=permit_read),
        type=discord.ChannelType.text
    )

    if race_channel is not None:
        new_room = PrivateRaceRoom(
            race_discord_channel=race_channel,
            race_private_info=race_private_info,
            admin_as_member=discord_member)
        await new_room.initialize()
        Necrobot().register_bot_channel(race_channel, new_room)

    return race_channel
Ejemplo n.º 2
0
    async def createchannel(message: discord.Message, arguments: str):
        global temp_channels
        server = message.server
        args = arguments.rsplit()
        name = args[0]
        everyone_perms = discord.PermissionOverwrite(read_messages=False)
        member_perms = discord.PermissionOverwrite(read_messages=True,
                                                   manage_channels=True)
        author_perms = discord.PermissionOverwrite(read_messages=True,
                                                   manage_channels=True,
                                                   manage_roles=True)
        everyone = discord.ChannelPermissions(target=server.default_role,
                                              overwrite=everyone_perms)

        access = [
            discord.ChannelPermissions(target=message.author,
                                       overwrite=author_perms), everyone
        ]
        for person in message.mentions:
            access.append(
                discord.ChannelPermissions(target=person,
                                           overwrite=member_perms))
        channel = await shinobu.create_channel(server, args[0], *access)
        await shinobu.edit_channel(channel,
                                   topic="What is this channel about?")
Ejemplo n.º 3
0
async def make_private_room(race_private_info, discord_member):
    # Define permissions
    deny_read = discord.PermissionOverwrite(read_messages=False)
    permit_read = discord.PermissionOverwrite(read_messages=True)

    # Make a channel for the room
    # noinspection PyUnresolvedReferences
    race_channel = await server.client.create_channel(
        server.server,
        get_raceroom_name(race_private_info.race_info),
        discord.ChannelPermissions(target=server.server.default_role,
                                   overwrite=deny_read),
        discord.ChannelPermissions(target=server.server.me,
                                   overwrite=permit_read),
        discord.ChannelPermissions(target=discord_member,
                                   overwrite=permit_read),
        type=discord.ChannelType.text)

    if race_channel is None:
        return None

    # Put the race channel in the races category
    race_channel_category = server.find_channel(
        channel_name=Config.RACE_CHANNEL_CATEGORY_NAME)
    if race_channel_category is not None:
        await discordutil.set_channel_category(channel=race_channel,
                                               category=race_channel_category)

    new_room = PrivateRaceRoom(race_discord_channel=race_channel,
                               race_private_info=race_private_info,
                               admin_as_member=discord_member)
    await new_room.initialize()
    Necrobot().register_bot_channel(race_channel, new_room)

    return race_channel
Ejemplo n.º 4
0
async def on_message(message):
    try:
        firehose = discord.utils.find(lambda m: m.name == "firehose",
                                      message.server.channels)
    except:
        await trainsbot.send_message(message.channel, "Something went wrong")
    if message.channel.name != "firehose":
        unfdmsg = "{0.channel} **|** {0.author.display_name}: {0.content}"
        await trainsbot.send_message(firehose, unfdmsg.format(message))
    if message.content.startswith("!invite"):
        try:
            fmt2 = "landing-{0.author.id}"
            everyone_perms = discord.PermissionOverwrite(read_messages=False)
            mine_perms = discord.PermissionOverwrite(read_messages=True)
            mine = discord.ChannelPermissions(target=message.server.me,
                                              overwrite=mine_perms)
            everyone = discord.ChannelPermissions(
                target=message.server.default_role, overwrite=everyone_perms)
            newchan = await trainsbot.create_channel(message.server,
                                                     fmt2.format(message),
                                                     everyone, mine)
            invite = await trainsbot.create_invite(destination=newchan,
                                                   max_uses=1)
            await trainsbot.send_message(
                message.channel,
                "Your invite is awaiting approval, thank you.")
            adminchannel = discord.utils.find(lambda m: m.name == "admins",
                                              message.server.channels)
            fmt = "User {0.author} has requested an invite. Invite code: {1.code}"
            await trainsbot.send_message(adminchannel,
                                         fmt.format(message, invite))
        except Exception as e:
            print(e)
Ejemplo n.º 5
0
    async def prepare(self):
        self.player_role = await self.bot.create_role(self.server,
                                                      name="Mystery Player")
        self.observer_role = await self.bot.create_role(
            self.server, name="Mystery Observer")
        self.dead_role = await self.bot.create_role(self.server,
                                                    name="Location")

        everyone_perm = discord.ChannelPermissions(
            target=self.server.default_role,
            overwrite=discord.PermissionOverwrite(read_messages=False,
                                                  send_messages=False))
        player_perm = discord.ChannelPermissions(
            target=self.player_role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=True))
        observer_perm = discord.ChannelPermissions(
            target=self.observer_role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=False))
        dead_perm = discord.ChannelPermissions(
            target=self.dead_role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=True))

        self.channel = await self.bot.create_channel(
            self.server, "%slobby" % (self.channel_prefix), everyone_perm,
            player_perm, observer_perm, dead_perm)

        await self.bot.edit_channel(self.channel, topic="Mystery game lobby.")

        self.game_state = self.STATE_LOBBY

        for location in self.locations:
            await location.start()
Ejemplo n.º 6
0
async def create_private_channel(ctx, channel_name, *users: discord.User):
    '''Create a private channel named name, and then add users.'''

    #Initialize server as the server in which this command is being run from
    server = ctx.message.server
    #Ensure the channel has at least one user
    if not users:
        await client.say("Usage:  create_private_channel <name> <users...>")

    #Deny everyone read_messages permissions
    #Grant Group read_messages permissions
    everyone_perms = discord.PermissionOverwrite(read_messages=False)
    group_perms = discord.PermissionOverwrite(read_messages=True)

    #overwrite the channel default with deny everyone rule
    everyone = discord.ChannelPermissions(target=server.default_role,
                                          overwrite=everyone_perms)

    #Make a group that includes the listed users and the bot- add this to the overwrite
    group = []
    group.append(
        discord.ChannelPermissions(target=server.me, overwrite=group_perms))
    for user in users:
        group.append(
            discord.ChannelPermissions(target=user, overwrite=group_perms))

    #create the channel as a text channel with "everyone" and "group" overwrite permissions
    await client.create_channel(server,
                                channel_name,
                                everyone,
                                *group,
                                type=discord.ChannelType.text)
    await asyncio.sleep(3)
Ejemplo n.º 7
0
    async def private(self, ctx, nom, perso):

        if nom in self.pv_chan.values():
            print("nom deja existant !")

        else:
            everyone_perms = discord.PermissionOverwrite(connect=False)
            pv_perms = discord.PermissionOverwrite(connect=True)

            everyone = discord.ChannelPermissions(
                target=self.server.default_role, overwrite=everyone_perms)
            pv = discord.ChannelPermissions(target=ctx.message.author,
                                            overwrite=pv_perms)

            self.pv_chan[nom] = await self.bot.create_channel(
                self.server, nom, everyone, pv, type=discord.ChannelType.voice)
            """for player in perso:
                test"""
            print(perso)

            embed = discord.Embed(title="Channeller priver",
                                  description="Info",
                                  color=0xff0000)
            embed.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
            embed.add_field(
                name="Priver",
                value="Channel créé ! Déplacement automatique...",
                inline=True)
            await self.bot.say(embed=embed)
            print("Channel " + str(nom) + " créé par: " +
                  str(ctx.message.author))
            await self.bot.move_member(ctx.message.author, self.pv_chan[nom])
Ejemplo n.º 8
0
async def make_match_room(match: Match, register=False) -> MatchRoom or None:
    """Create a discord.Channel and a corresponding MatchRoom for the given Match. 
    
    Parameters
    ----------
    match: Match
        The Match to create a room for.
    register: bool
        If True, will register the Match in the database.

    Returns
    -------
    Optional[MatchRoom]
        The created room object.
    """
    # Check to see the match is registered
    if not match.is_registered:
        if register:
            await match.commit()
        else:
            console.warning('Tried to make a MatchRoom for an unregistered Match ({0}).'.format(match.matchroom_name))
            return None

    # Check to see if we already have the match channel
    channel_id = match.channel_id
    match_channel = server.find_channel(channel_id=channel_id) if channel_id is not None else None

    # If we couldn't find the channel or it didn't exist, make a new one
    if match_channel is None:
        # Create permissions
        deny_read = discord.PermissionOverwrite(read_messages=False)
        permit_read = discord.PermissionOverwrite(read_messages=True)
        racer_permissions = []
        for racer in match.racers:
            if racer.member is not None:
                racer_permissions.append(discord.ChannelPermissions(target=racer.member, overwrite=permit_read))

        # Make a channel for the room
        # noinspection PyUnresolvedReferences
        match_channel = await server.client.create_channel(
            server.server,
            get_matchroom_name(match),
            discord.ChannelPermissions(target=server.server.default_role, overwrite=deny_read),
            discord.ChannelPermissions(target=server.server.me, overwrite=permit_read),
            *racer_permissions,
            type=discord.ChannelType.text)

        if match_channel is None:
            console.warning('Failed to make a match channel.')
            return None

    # Make the actual RaceRoom and initialize it
    match.set_channel_id(int(match_channel.id))
    new_room = MatchRoom(match_discord_channel=match_channel, match=match)
    Necrobot().register_bot_channel(match_channel, new_room)
    await new_room.initialize()

    return new_room
Ejemplo n.º 9
0
async def setup(ctx):
    author = ctx.message.author
    server = ctx.message.server
    mod_perms = discord.Permissions(manage_messages=True,
                                    kick_members=True,
                                    manage_nicknames=True,
                                    mute_members=True)
    admin_perms = discord.Permissions(ADMINISTRATOR=True)

    await client.create_role(author.server,
                             name="Owner",
                             permissions=admin_perms)
    await client.create_role(author.server,
                             name="Admin",
                             permissions=admin_perms)
    await client.create_role(author.server,
                             name="Senior Moderator",
                             permissions=mod_perms)
    await client.create_role(author.server, name="G.O.H")
    await client.create_role(author.server,
                             name="Moderator",
                             permissions=mod_perms)
    await client.create_role(author.server, name="Muted")

    await client.create_role(author.server, name="Friend of Owner")
    await client.create_role(author.server, name="Verified")
    everyone_perms = discord.PermissionOverwrite(send_messages=False,
                                                 read_messages=True)
    everyone = discord.ChannelPermissions(target=server.default_role,
                                          overwrite=everyone_perms)
    user_perms = discord.PermissionOverwrite(read_messages=True)
    user = discord.ChannelPermissions(target=server.default_role,
                                      overwrite=user_perms)
    private_perms = discord.PermissionOverwrite(read_messages=False)
    private = discord.ChannelPermissions(target=server.default_role,
                                         overwrite=private_perms)
    await client.create_channel(server, '🎉welcome🎉', everyone)
    await client.create_channel(server, '🎯rules🎯', everyone)
    await client.create_channel(server, '🎥featured-content🎥', everyone)
    await client.create_channel(server, '📢announcements📢', everyone)
    await client.create_channel(server, '📢vote_polls📢', everyone)
    await client.create_channel(server, 'private_chat', private)
    await client.create_channel(server, '🎮general_chat🎮', user)
    await client.create_channel(server, '🎮general_media🎮', user)
    await client.create_channel(server, '👍bots_zone👍', user)
    await client.create_channel(server, '🎥youtube_links🎥', user)
    await client.create_channel(server, '🎥giveaway_links🎥', user)
    await client.create_channel(server, '🎥other_links🎥', user)
    await client.create_channel(server,
                                '🔥Music Zone🔥',
                                type=discord.ChannelType.voice)
    await client.create_channel(server, '🔥music_command🔥s', user)
    await client.create_channel(server,
                                '🔥Chill Zone🔥',
                                type=discord.ChannelType.voice)
Ejemplo n.º 10
0
async def addchannel(server, channel_name, channel_type_str):
    if channel_type_str == 'text':
        channel_type = discord.ChannelType.text
    else:
        channel_type = discord.ChannelType.voice

    everyone_perms = discord.PermissionOverwrite(read_messages=False)
    my_perms = discord.PermissionOverwrite(read_messages=True)
    everyone = discord.ChannelPermissions(target=server.default_role, overwrite=everyone_perms)
    mine = discord.ChannelPermissions(target=server.me, overwrite=my_perms)
    await client.create_channel(server, channel_name, everyone, mine, type=channel_type)
Ejemplo n.º 11
0
    async def claim(self, ctx):
        server = ctx.message.server
        claimer = ctx.message.author
        ticket = ctx.message.content[14:]

        if ticket == "":
            await self.bot.say("Please input a ticket id")
            return

        with open("data/claimedticketids.json", "r") as f:
            ticket_claims = json.load(f)

        a = open("data/tickets.json").read()
        tickets = json.loads(a)

        if ticket not in ticket_claims:
            await self.bot.say("No ticket with that ID was found")
            return

        if ticket_claims[ticket] != "not_claimed":
            await self.bot.say("This ticket is already claimed.")
            return

        ticket_claims[ticket] = claimer.id
        role = discord.utils.get(server.roles, name="Overseer")
        user = await self.bot.get_user_info(
            tickets[ticket]["ticket_data"][0][u'issuer_id'])

        ticket_perms = discord.PermissionOverwrite(read_messages=True)
        everyone_perms = discord.PermissionOverwrite(read_messages=False)

        techlead = discord.ChannelPermissions(target=role,
                                              overwrite=ticket_perms)
        everyone = discord.ChannelPermissions(target=server.default_role,
                                              overwrite=everyone_perms)
        ticketuser = discord.ChannelPermissions(target=user,
                                                overwrite=ticket_perms)
        claimeruser = discord.ChannelPermissions(target=ctx.message.author,
                                                 overwrite=ticket_perms)

        await self.bot.create_channel(server, "Ticket Nr. {}".format(ticket),
                                      ticketuser, everyone, techlead,
                                      claimeruser)

        with open("data/claimedticketids.json", "w") as f:
            json.dump(ticket_claims, f)

        channel = discord.utils.get(ctx.message.server.channels,
                                    name="tickets")
        await self.bot.send_message(
            channel, claimer.name + " has claimed the ticket nr. " + ticket)

        await self.bot.say("You have claimed the ticket nr. " + ticket)
Ejemplo n.º 12
0
async def ticket(ctx,*, content):
    everyone_perms = discord.PermissionOverwrite(read_messages=False)
    my_perms = discord.PermissionOverwrite(read_messages=True)

    everyone = discord.ChannelPermissions(target=ctx.message.server.default_role, overwrite=everyone_perms)
    mine = discord.ChannelPermissions(ctx.message.author, overwrite=my_perms)
    test = await bot.create_channel(ctx.message.server, 'ticket', everyone, mine)
    await bot.delete_message(ctx.message)
    await asyncio.sleep(2)
    msg = 'Hello pls wait for staff to come'
    for servers in bot.servers:
        for channel in servers.channels:
            if channel.name == 'ticket':
                await bot.send_message(channel, msg)
Ejemplo n.º 13
0
    async def c_initmod(self, message, args, cxt):
        '''`j!initmod modchannel logchannel` - Initialize Moderator extension in this server'''
        await self.is_admin(message.author.id)

        if len(args) < 3:
            await cxt.say(self.c_initmod.__doc__)
            return

        server = message.server
        server_id = message.server.id

        if server_id in self.moddb:
            await cxt.say("Moderator is already running on in this server")
            return

        try:
            mod_channel_name = args[1]
            log_channel_name = args[2]
        except:
            await cxt.say("???")
            return

        # everyone can read, only jose can write
        everyone_perms = discord.PermissionOverwrite(read_messages=True,
                                                     write_messages=False)
        my_perms = discord.PermissionOverwrite(read_messages=True,
                                               write_messages=True)

        everyone = discord.ChannelPermissions(target=server.default_role,
                                              overwrite=everyone_perms)
        jose = discord.ChannelPermissions(target=server.me, overwrite=my_perms)

        try:
            mod_channel = await self.client.create_channel(server, \
                mod_channel_name, everyone, jose)
            log_channel = await self.client.create_channel(server, \
                log_channel_name, everyone, jose)
        except discord.Forbidden:
            await cxt.say("hey I can't create channels give me permissions")
            return

        self.moddb[server_id] = {
            'mod_channel': mod_channel.id,
            'log_channel': log_channel.id,
            'logs': {
                '0': 'Genesis log'
            },
        }

        return
Ejemplo n.º 14
0
    async def handle_log_channel(self, server):
        # Check if the channel already exists
        if not [
                ch for ch in server.channels
                if ch.name == self.handler.get_var(server.id, "logchannel")
        ]:

            if not self.handler.get_var(server.id, "logchannel"):
                return None

            # Creates permission overwrites: normal users cannot see the channel, only users with the role "Nano Admin" and the bot
            them = discord.PermissionOverwrite(read_messages=False,
                                               send_messages=False,
                                               read_message_history=False)
            us = discord.PermissionOverwrite(read_messages=True,
                                             send_messages=True,
                                             read_message_history=True,
                                             attach_files=True,
                                             embed_links=True,
                                             manage_messages=True)

            admins = discord.utils.find(lambda m: m.name == "Nano Admin",
                                        server.roles)

            if admins:
                admin_perms = discord.ChannelPermissions(target=admins,
                                                         overwrite=us)
            else:
                admin_perms = None

            them_perms = discord.ChannelPermissions(target=server.default_role,
                                                    overwrite=them)
            nano_perms = discord.ChannelPermissions(target=server.me,
                                                    overwrite=us)

            log_channel_name = self.handler.get_var(server.id, "logchannel")

            if admins:
                return await self.client.create_channel(
                    server, log_channel_name, admin_perms, them_perms,
                    nano_perms)

            else:
                return await self.client.create_channel(
                    server, log_channel_name, them_perms, nano_perms)

        else:
            return discord.utils.find(
                lambda m: m.name == self.handler.get_var(
                    server.id, "logchannel"), server.channels)
Ejemplo n.º 15
0
    async def AutoTempVoice(
            self, before,
            user):  #Is called when Someone joins the voice channel - Listener
        """Automaticly checks the voice channel for users and makes a channel for them"""

        # I cannot have any returns here so channels will be created
        if before.voice_channel is not None:
            # Did they come from a channel?

            if before.voice_channel.id in self.check_empty:
                #Was the channel they where in a tempary channel?

                if len(before.voice_channel.voice_members) == 0:
                    # How many people are in the channel?
                    # if zero => empty. Therefore, remove the channel
                    await self.bot.delete_channel(
                        self.bot.get_channel(before.voice_channel.id))
                    self.check_empty.remove(before.voice_channel.id)

        if user.voice_channel is None:  # Are they in a channel right now?
            return

        if self.settings[user.voice_channel.server.id]['type'] != True:
            return

        try:
            if self.settings[user.voice_channel.server.
                             id]['channel'] != user.voice_channel.id:
                return

            position = user.voice_channel.position
            perms = discord.PermissionOverwrite(
                mute_members=True, deafen_members=True,
                manage_channels=True)  #Sets permisions
            perms = discord.ChannelPermissions(
                target=user, overwrite=perms
            )  #Sets the channel permissions for the person who sent the message

            channel = await self.bot.create_channel(
                user.voice_channel.server,
                user.name,
                perms,
                type=discord.ChannelType.voice)  #creates a channel

            self.check_empty.append(channel.id)  #Multidimentional list
            dataIO.save_json("data/Tasty/TempVoice/VoiceChannel.json",
                             self.check_empty)  #saves the new file

            await self.channel_to_category(
                user.voice_channel.id,
                channel.id)  #puts channel into the right category
            await self.bot.move_member(user, channel)
            await self.bot.move_channel(channel, position + 1)

        except discord.Forbidden:
            await self.bot.send_message(
                user.server.owner,
                "I need the proper permissions! I was unable to create a new channel. (Move members, Manage channels)"
            )
Ejemplo n.º 16
0
async def setupwelcome(ctx):
    if ctx.message.author.bot:
      return
    else:
      server = ctx.message.server
      everyone_perms = discord.PermissionOverwrite(send_messages=False, read_messages=True)
      everyone = discord.ChannelPermissions(target=server.default_role, overwrite=everyone_perms)
      await client.create_channel(server, '🎉-welcome-🎊',everyone)
Ejemplo n.º 17
0
 async def _make_hidden_channel(self, ctx, channel_name: str):
     """
     隠れチャンネルを作成します。
     使用例「!mkhidden new_channel_name」
     """
     server = ctx.message.server
     everyone_perm = discord.ChannelPermissions(target=server.default_role,
                                                overwrite=HIDDEN_OVERWRITE)
     await self.bot.create_channel(server, channel_name, everyone_perm)
Ejemplo n.º 18
0
    async def voice(self, ctx, *, name: str = ''):  #actual command
        """Creates a voice channel use opptional argument <name> to spesify the name of the channel, Use `" "` around the name of the channel"""

        #Checks the mode (type = True (therefore mode = [1])
        if self.settings[ctx.message.server.id]['type'] != False:
            return

        if name == '':  #Tests if no name was passed
            name = ctx.message.author.name  #Sets it to the name of whoever sent the message

        server_role = self.settings[ctx.message.server.id]['role']
        if server_role is not None:
            for role in set(ctx.message.author.roles):
                if role.id == server_role:
                    break  # If role is found

            else:  #If we didn't break out of the loop then the user does not have the right role
                await self.bot.say(
                    "Sorry but you are not permited to use that command! A role is needed."
                )
                return  # If role is found breaks loop - else statement isn't executed.

        #If all the requirements are met
        try:
            perms = discord.PermissionOverwrite(
                mute_members=True, deafen_members=True,
                manage_channels=True)  #Sets permisions
            perms = discord.ChannelPermissions(
                target=ctx.message.author, overwrite=perms
            )  #Sets the channel permissions for the person who sent the message
            channel = await self.bot.create_channel(
                ctx.message.server,
                name,
                perms,
                type=discord.ChannelType.voice)  #creates a channel
            await self.move_channel_to_category(
                channel.id, self.settings[channel.server.id]['category'])
            self.check_empty.append(channel.id)  #Multidimentional list
            dataIO.save_json("data/Tasty/TempVoice/VoiceChannel.json",
                             self.check_empty)  #saves the new file
            return

        except discord.Forbidden:
            await self.bot.send_message(
                ctx.message.channel,
                "I don't have the right perrmissions for that! (I need to be able to manage channels)"
            )

        except Exception as e:  # if something else happens such as it's not connected or a file has been messed with and so doesn't show an error in discord channel
            print("=================")
            print(e)
            print("=================")

            await self.bot.send_message(ctx.message.channel,
                                        "An error occured - check logs")
Ejemplo n.º 19
0
async def summon(message, parsed_args):
    """Create a mirrored channel pair."""
    private_channel_tuple = namedtuple("private_channel_pair",
                                       ["user_channel", "admin_channel"])

    server = message.server
    everyone_role = server.default_role
    server_id = server.id
    admin_role = servers[server_id]["admin_role"]
    author = message.author
    channel_name = f"{author.name}-Talking to admins"
    channel_name_admin = channel_name + "-Admin only side"

    denied_perms = discord.PermissionOverwrite(read_messages=False)
    allowed_perms = discord.PermissionOverwrite(read_messages=True)

    everyone = discord.ChannelPermissions(target=everyone_role,
                                          overwrite=denied_perms)
    admin = discord.ChannelPermissions(target=admin_role,
                                       overwrite=allowed_perms)
    admin_no = discord.ChannelPermissions(target=admin_role,
                                          overwrite=denied_perms)
    user = discord.ChannelPermissions(target=author, overwrite=allowed_perms)
    bot_perms = discord.ChannelPermissions(target=bot.user,
                                           overwrite=denied_perms)

    new_user_channel = await bot.create_channel(server, channel_name, everyone,
                                                admin_no, user, bot_perms)
    new_admin_channel = await bot.create_channel(server, channel_name_admin,
                                                 everyone, admin, bot_perms)
    new_channels = private_channel_tuple(new_user_channel, new_admin_channel)
    servers[server_id]["created_channels"].append(new_channels)
    await bot.delete_message(message)
    user_message = f"{author.mention} you can talk to the admins here."
    admin_message = (f"{author.mention} has opened a private channel with the "
                     "admins")
    await bot.send_message(new_user_channel, user_message)
    await bot.send_message(new_admin_channel, admin_message)
    return True
Ejemplo n.º 20
0
async def setw(ctx):
    if ctx.message.author.bot:
        return
    if ctx.message.author.server_permissions.administrator == False:
        await client.say('**You do not have permission to use this command**')
        return
    else:
        server = ctx.message.server
        everyone_perms = discord.PermissionOverwrite(send_messages=False,
                                                     read_messages=True)
        everyone = discord.ChannelPermissions(target=server.default_role,
                                              overwrite=everyone_perms)
        await client.create_channel(server, 'server-welcome', everyone)
Ejemplo n.º 21
0
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')
    discord_handles = get_privileges_handles_from_api()
    for server in client.servers:
        role = discord.utils.get(server.roles, name=our_role_name)
        if not role:
            print('Creating role {0} in {1}'.format(our_role_name, server))
            role = await client.create_role(server, name=our_role_name)
        else:
            print('Role {0} found at {1}'.format(our_role_name, server))
        channel = discord.utils.get(client.get_all_channels(),
                                    server__name=server.name,
                                    name=our_channel_name)
        if not channel:
            print('Creating channel {0} in {1}'.format(our_channel_name,
                                                       server))
            everyone_perms = discord.PermissionOverwrite(send_messages=False)
            owner_perms = discord.PermissionOverwrite(send_messages=True)
            everyone = discord.ChannelPermissions(target=server.default_role,
                                                  overwrite=everyone_perms)
            owners = discord.ChannelPermissions(target=role,
                                                overwrite=owner_perms)
            await client.create_channel(server, our_channel_name, everyone,
                                        owners)
        else:
            print('Channel {0} found at {1}'.format(channel, server))

        for member in server.members:
            if member.name in discord_handles and role not in member.roles:
                print('Adding role to {0} member'.format(member.name))
                await client.add_roles(member, role)
            elif member.name in discord_handles and role in member.roles:
                print('{0} already has our role'.format(member.name))
            else:
                print('{0} does not own our token'.format(member.name))
Ejemplo n.º 22
0
    async def create_user(self,
                          ctx,
                          name,
                          user: discord.Member,
                          after: discord.Channel = None):
        """User specific channel.

        Everyone can read but only one person can write.
        """
        server = ctx.message.server
        channel = await self.bot.create_channel(
            server,
            name,
            discord.ChannelPermissions(target=server.default_role,
                                       overwrite=discord.PermissionOverwrite(
                                           read_messages=True,
                                           send_messages=False)),
            discord.ChannelPermissions(
                target=user,
                overwrite=discord.PermissionOverwrite(send_messages=True)),
            type=discord.ChannelType.text)

        await self.bot.say("Channel created.")
Ejemplo n.º 23
0
    async def start(self):
        self.role = await self.game.bot.create_role(self.game.server,
                                                    name="Location")
        self.dead_role = await self.game.bot.create_role(self.game.server,
                                                         name="Location")

        everyone_perm = discord.ChannelPermissions(
            target=self.game.server.default_role,
            overwrite=discord.PermissionOverwrite(read_messages=False,
                                                  send_messages=False,
                                                  read_message_history=False))
        role_perm = discord.ChannelPermissions(
            target=self.role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=True,
                                                  read_message_history=False))
        observer_perm = discord.ChannelPermissions(
            target=self.game.observer_role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=False,
                                                  read_message_history=True))
        dead_perm = discord.ChannelPermissions(
            target=self.game.dead_role,
            overwrite=discord.PermissionOverwrite(read_messages=False,
                                                  send_messages=False,
                                                  read_message_history=False))
        dead_perm2 = discord.ChannelPermissions(
            target=self.dead_role,
            overwrite=discord.PermissionOverwrite(read_messages=True,
                                                  send_messages=False,
                                                  read_message_history=True))

        self.channel = await self.game.bot.create_channel(
            self.game.server, "%s%s" % (self.game.channel_prefix, self.name),
            everyone_perm, role_perm, observer_perm, dead_perm, dead_perm2)
        await self.game.bot.edit_channel(self.channel, topic=self.topic)
Ejemplo n.º 24
0
async def open(context):
    mafiaLobby = await bot.say("The Mafia Lobby has been opened! Type " +
                               prefix + "join to join.")

    gameInfo["open"] = True
    gameInfo["channel"] = await bot.create_channel(
        context.message.server, "mafia-general",
        discord.ChannelPermissions(
            context.message.server.default_role,
            discord.PermissionOverwrite(read_messages=False)))
    gameInfo["mafia_channel"] = await bot.create_channel(
        context.message.server, "mafia-private",
        discord.ChannelPermissions(
            context.message.server.default_role,
            discord.PermissionOverwrite(read_messages=False)))
    gameInfo["state"] = "Lobby"
    gameInfo["player_count"] = 0

    await bot.move_channel(gameInfo["channel"], 0)
    await bot.move_channel(gameInfo["mafia_channel"], 1)

    await bot.change_presence(game=discord.Game(name="Mafia [Lobby]"))

    players = {}
Ejemplo n.º 25
0
async def addchannel(ctx, channel: str = None):
    server = ctx.message.server
    if channel is None:
        await client.say("Please specify a channel name")
    else:
        if ctx.message.author.server_permissions.administrator == False:
            await client.say(
                '**You do not have permission to use this command**')
            return
        else:
            everyone_perms = discord.PermissionOverwrite(send_messages=None,
                                                         read_messages=None)
            everyone = discord.ChannelPermissions(target=server.default_role,
                                                  overwrite=everyone_perms)
            await client.create_channel(server, channel, everyone)
            await client.say("{} channel has been created.".format(channel))
Ejemplo n.º 26
0
async def setreactionverify(ctx):
    author = ctx.message.author
    server = ctx.message.server
    everyone_perms = discord.PermissionOverwrite(send_messages=False,
                                                 read_messages=True)
    everyone = discord.ChannelPermissions(target=server.default_role,
                                          overwrite=everyone_perms)
    await client.create_channel(server, '★verify-for-chatting★', everyone)
    for channel in author.server.channels:
        if channel.name == '★verify-for-chatting★':
            react_message = await client.send_message(
                channel,
                'React with 🇻 to Verify | Sometimes it not works so you can also use mv!verify anywhere(Where you can send messages)'
            )
            reaction = '🇻'
            await client.add_reaction(react_message, reaction)
Ejemplo n.º 27
0
async def setreactionverify(ctx):
    author = ctx.message.author
    server = ctx.message.server
    everyone_perms = discord.PermissionOverwrite(send_messages=False,
                                                 read_messages=True)
    everyone = discord.ChannelPermissions(target=server.default_role,
                                          overwrite=everyone_perms)
    await client.create_channel(server, '★verify-for-chatting★', everyone)
    for channel in author.server.channels:
        if channel.name == '★verify-for-chatting★':
            react_message = await client.send_message(
                channel,
                'React with <a:happy:516183323052212236> to Verify | This verification system is to prevent our server from those who join and try to spam from self bots'
            )
            reaction = 'a:happy:516183323052212236'
            await client.add_reaction(react_message, reaction)
Ejemplo n.º 28
0
    async def voice(self, ctx, name:str=''): #actual command
        """Creates a voice channel use opptional argument <name> to spesify the name of the channel"""
        if name =='': #Tests if no name was passed
            name = ctx.message.author.name #Sets it to the name of whoever sent the message

        
        try:
            perms = discord.PermissionOverwrite(mute_members=True, deafen_members=True, manage_channels=True)#Sets permisions
            perms = discord.ChannelPermissions(target=ctx.message.author, overwrite=perms)#Sets the channel permissions for the person who sent the message
            channel = await self.bot.create_channel(ctx.message.server, name, perms, type=discord.ChannelType.voice)#creates a channel          
            self.check_empty.append([channel.id, ctx.message.server.id]) #Multidimentional list or array
            dataIO.save_json("data/Tasty/VoiceChannel.json", self.check_empty)#saves the new file
            
        except Exception as e:
            print(e)
            await self.bot.send_message(ctx.message.channel, "An error occured - check logs")
            pass
Ejemplo n.º 29
0
async def setup(bot, message, **kwargs):
    if (message.author is message.server.owner) and (message.channel
                                                     is not bot.conf.pug_chan):
        mention = '<@{}> '.format(message.author.id)

        #confirm
        await bot.client.send_message(message.channel,
                                      mention + STR_SETUP_CONFIRM)
        check = await bot.client.wait_for_message(timeout=30,
                                                  author=message.author,
                                                  channel=message.channel)

        if check is None:
            raise CommandError('Setup timed out.')
        elif not check.content.startswith('y'):
            raise CommandError('Setup cancelled.')

        #setup broadcast channel - MANDATORY
        await bot.client.send_message(message.channel,
                                      mention + STR_SETUP_CHAN)
        check_brd_chan = await bot.client.wait_for_message(
            timeout=30, author=message.author, channel=message.channel)

        if check_brd_chan is None:
            raise CommandError('Setup timed out.')

        temp_brd_chan = discord.utils.get(message.server.channels,
                                          name=check_brd_chan.content)
        if temp_brd_chan is None or temp_brd_chan.id == bot.conf.pug_chan.id:
            raise CommandError(
                'Setup cancelled. Invalid channel or doesn\'t exist.')
        elif not temp_brd_chan.permissions_for(bot.server.me).send_messages:
            raise CommandError(
                'Setup cancelled. That channel does not have proper permissions.'
            )
        else:
            brd_chan = temp_brd_chan
            await bot.client.send_message(
                message.channel, mention +
                'Broadcast channel set to <#{}>.'.format(brd_chan.id))

        #setup pug role
        await bot.client.send_message(message.channel,
                                      mention + STR_SETUP_PUG_ROLE)
        check_pug_role = await bot.client.wait_for_message(
            timeout=30, author=message.author, channel=message.channel)

        if check_pug_role is None:
            raise CommandError('Setup timed out.')

        temp_pug_role = discord.utils.get(message.server.roles,
                                          name=check_pug_role.content)

        if temp_pug_role is None:
            pug_role = message.server.default_role
            await bot.client.send_message(message.channel,
                                          mention + STR_SETUP_BAD_ROLE)
        else:
            pug_role = temp_pug_role
            await bot.client.send_message(
                message.channel,
                mention + 'PUG role set to {}.'.format(pug_role.name))

        #setup mod role
        await bot.client.send_message(message.channel,
                                      mention + STR_SETUP_MOD_ROLE)
        check_mod_role = await bot.client.wait_for_message(
            timeout=30, author=message.author, channel=message.channel)

        if check_mod_role is None:
            raise CommandError('Setup timed out.')

        temp_mod_role = discord.utils.get(message.server.roles,
                                          name=check_mod_role.content)

        if temp_mod_role is None or temp_mod_role is message.server.default_role or temp_mod_role.id == pug_role.id:
            mod_role = discord.Object(id='')
            await bot.client.send_message(message.channel,
                                          mention + STR_SETUP_BAD_ROLE)
        else:
            mod_role = temp_mod_role
            await bot.client.send_message(
                message.channel,
                mention + 'Moderator role set to {}.'.format(mod_role.name))

        #save settings
        try:
            everyone_perms = discord.PermissionOverwrite(
                add_reactions=True,
                send_messages=True,
                send_tts_messages=False,
                attach_files=False)
            this_bot_perms = discord.PermissionOverwrite(
                add_reactions=True,
                send_messages=True,
                manage_messages=True,
                read_message_history=True)

            everyone = discord.ChannelPermissions(
                target=message.server.default_role, overwrite=everyone_perms)
            this_bot = discord.ChannelPermissions(target=message.server.me,
                                                  overwrite=this_bot_perms)
            pug = await bot.client.create_channel(
                message.server,
                'pickup-games',
                everyone,
                this_bot,
                type=discord.ChannelType.text)

            topic_fmt = ' '.join([x for x in bot.conf.modes])
            topic_msg = 'Type !create <gamemode> to make a lobby. Available gamemodes: {}'.format(
                *topic_fmt)
            await bot.client.edit_channel(pug, topic=topic_msg)
        except discord.DiscordException as e:
            await bot.client.send_message(
                message.channel,
                mention + 'Error: Setup failed.\n{}'.format(e.args))
        else:
            bot.conf.pug_chan = pug
            bot.conf.brd_chan = brd_chan
            bot.conf.pug_role = pug_role
            bot.conf.mod_role = mod_role
            bot.dump_config()
            await bot.client.send_message(message.channel,
                                          mention + STR_SETUP_SUCCESS)
            await bot.on_ready()
Ejemplo n.º 30
0
 async def on_member_join(self, member):
     server = member.server
     channel = server.default_channel
     if member.bot:  # BotRights
         return
     if server.id not in self.settings:
         self.settings[server.id] = default_settings
         dataIO.save_json('data/bouncer/settings.json', self.settings)
     settings = self.settings[server.id]
     if not settings["on"]:
         return
     perms = channel.permissions_for(server.me)
     manage_channels = perms.manage_channels
     add_reactions = perms.add_reactions
     kick_members = perms.kick_members
     manage_roles = perms.manage_roles
     read_messages = perms.read_messages
     send_messages = perms.send_messages
     can_proceed = manage_channels and add_reactions and kick_members and manage_roles and read_messages and send_messages
     if not can_proceed:
         error = (
             "Permission missing. Neccesary permissions: Manage channels, "
             "add reactions, kick members, manage roles, read messages, send messages"
         )
         print(error)
         await self.writelog(server, error)
         return
     mode = settings["mode"]
     role_before = discord.utils.get(
         server.roles,
         id=settings["role_before"]) if settings["role_before"] else None
     role_after = discord.utils.get(server.roles, id=settings["role_after"])
     rules = settings["rules"]
     welcome_message = settings["welcome_message"]
     kick_message = settings["kick_message"]
     timeout_message = settings["timeout_message"]
     if not role_after:
         error = "After-role is not set, aborting"
         print(error)
         await self.writelog(server, error)
         return
     if not kick_message or not welcome_message:
         error = "Missing message in settings, aborting"
         print(error)
         await self.writelog(server, error)
         return
     if role_before:
         await self.bot.add_roles(member, role_before)
     try:
         if mode == "dm":
             result = await self.bounce(member,
                                        rules.format(member,
                                                     server), member)
             if result:
                 await self.bot.send_message(member, welcome_message)
                 if role_before:
                     await self.bot.remove_roles(member, role_before)
                 await self.bot.add_roles(member, role_after)
                 await self.writelog(
                     server,
                     "{0.name} has accepted the rules".format(member))
             if not result and result is not None:
                 await self.bot.send_message(member, kick_message)
                 await self.bot.kick(member)
                 await self.writelog(
                     server,
                     "{0.name} has denied the rules and been kicked".format(
                         member))
             elif result is None:
                 await self.bot.send_message(member, timeout_message)
                 await self.bot.kick(member)
                 await self.writelog(
                     server, "{0.name} has timed out".format(member))
         else:
             channel_name = "Welcome_" + member.id
             everyone_perms = discord.PermissionOverwrite(
                 read_messages=False)
             user_perms = discord.PermissionOverwrite(
                 read_messages=True,
                 add_reactions=False,
                 read_message_history=True)
             bot_perms = discord.PermissionOverwrite(read_messages=True,
                                                     add_reaction=True,
                                                     manage_channels=True)
             everyone = discord.ChannelPermissions(
                 target=server.default_role, overwrite=everyone_perms)
             user = discord.ChannelPermissions(target=member,
                                               overwrite=user_perms)
             bot = discord.ChannelPermissions(target=server.me,
                                              overwrite=bot_perms)
             channel = await self.bot.create_channel(
                 server, channel_name, everyone, user, bot)
             result = await self.bounce(channel,
                                        rules.format(member,
                                                     server), member)
             if result:
                 await self.bot.send_message(channel, welcome_message)
                 if role_before:
                     await self.bot.remove_roles(member, role_before)
                 await self.bot.add_roles(member, role_after)
                 await self.writelog(
                     server,
                     "{0.name} has accepted the rules".format(member))
                 await asyncio.sleep(180)
                 await self.bot.delete_channel(channel)
             if not result and result is not None:
                 await self.bot.delete_channel(channel)
                 await self.bot.send_message(member, kick_message)
                 await self.bot.kick(member)
                 await self.writelog(
                     server,
                     "{0.name} has denied the rules and been kicked".format(
                         member))
             elif result is None:
                 await self.bot.delete_channel(channel)
                 await self.bot.send_message(member, timeout_message)
                 await self.bot.kick(member)
                 await self.writelog(
                     server, "{0.name} has timed out".format(member))
     except discord.errors.Forbidden:
         print("Missing neccesary permisions. Ugh..")
         await self.writelog(
             server, "Missing some permission, member might be stuck")
     except Exception as e:
         print("[Bouncer]. Error: {}".format(e))
         await self.writelog(
             server,
             "Unknown exception occured: {}. User is probably stuck,".
             format(e))