示例#1
0
 async def _send(self, ctx, user: discord.Member):
     """Send a user to Coventry"""
     if user is None:
         await self.bot.say("Hey, you didn't specify a user!")
     else:
         server = ctx.message.server
         for usr in ctx.message.mentions:
             if usr != ctx.message.author:
                 is_mod_or_admin = False
                 for r in usr.roles:
                     if r.name == settings.get_server_mod(
                             ctx.message.server):
                         is_mod_or_admin = True
                     elif r.name == settings.get_server_admin(
                             ctx.message.server):
                         is_mod_or_admin = True
                 if not is_mod_or_admin:
                     chrolename = usr.name + usr.discriminator
                     covrole = await self.bot.create_role(server,
                                                          name=chrolename)
                     await self.bot.add_roles(usr, covrole)
                     admin_role = discord.utils.get(
                         server.roles,
                         name=settings.get_server_admin(server))
                     mod_role = discord.utils.get(
                         server.roles, name=settings.get_server_mod(server))
                     everyone_perms = discord.PermissionOverwrite(
                         read_messages=False)
                     insilenced_perms = discord.PermissionOverwrite(
                         read_messages=True, send_messages=True)
                     mod_admin_perms = discord.PermissionOverwrite(
                         read_messages=True,
                         send_messages=True,
                         manage_channel=True)
                     chn = await self.bot.create_channel(server, chrolename,\
                         (server.default_role, everyone_perms),\
                         (covrole, insilenced_perms),\
                         (mod_role, mod_admin_perms),\
                         (admin_role, mod_admin_perms))
                     await asyncio.sleep(1)
                     for c in server.channels:
                         if c.name != chn.name:
                             try:
                                 await self.bot.edit_channel_permissions(
                                     c, covrole, everyone_perms)
                             except discord.errors.Forbidden:
                                 pass
             await self.bot.say("Done")
示例#2
0
 async def admin_or_owner(self, message):
     if message.author.id == bot_settings.owner:
         return True
     elif discord.utils.get(message.author.roles, name=bot_settings.get_server_admin(message.server)) is not None:
         return True
     else:
         return False
示例#3
0
 def predicate(ctx):
     server = ctx.message.server
     mod_role = settings.get_server_mod(server).lower()
     admin_role = settings.get_server_admin(server).lower()
     return role_or_permissions(
         ctx, lambda r: r.name.lower() in (mod_role, admin_role, "sensei"),
         **perms)
示例#4
0
	async def skip(self, ctx):
		"""Skips a shitty song"""
		server = ctx.message.server
		user = ctx.message.author
		admin_role = settings.get_server_admin(server)
		mod_role = settings.get_server_mod(server)
		instaskip = user.id == settings.owner or user == server.owner or discord.utils.get(user.roles, name=admin_role) is not None or discord.utils.get(user.roles, name=mod_role) is not None
		
		if server.id not in self.players:
			await self.bot.say("Can't skip if I'm not playing")
			return
		
		if not instaskip:
			if server.id not in self.skip_votes:
				self.skip_votes[server.id] = []
			
			for id in self.skip_votes[server.id]:
				if user.id == id:
					self.skip_votes[server.id].remove(id)
					await self.bot.say("Vote to skip removed")
					return
			
			self.skip_votes[server.id].append(user.id)
			skips = len(self.skip_votes[server.id])
			members = sum(not m.bot for m in server.me.voice_channel.voice_members)
			
			votes = int(100 * skips / members)
		
		if instaskip or votes >= self.settings["vote_threshold"]:
			self.players[server.id].stop()
			await self.bot.say("Skipping")
		else:
			await self.bot.say(user.name + " voted to skip. " + str(votes) + "% out of " + str(self.settings["vote_threshold"]) + "% needed")
示例#5
0
 async def _new_message(self, message):
     """Finds the message and checks it for regex"""
     user = message.author
     if message.server is None:
         return
     if message.server.id in self.json:
         if self.json[message.server.id]['toggle'] is True:
             if self.regex.search(
                     message.content
             ) is not None or self.regex_discordme.search(
                     message.content) is not None:
                 roles = [r.name for r in user.roles]
                 bot_admin = settings.get_server_admin(message.server)
                 bot_mod = settings.get_server_mod(message.server)
                 if user.id == settings.owner:
                     return
                 elif bot_admin in roles:
                     return
                 elif bot_mod in roles:
                     return
                 elif user.permissions_in(
                         message.channel).manage_messages is True:
                     return
                 else:
                     asyncio.sleep(0.5)
                     await self.bot.delete_message(message)
                     if self.json[message.server.id]['dm'] is True:
                         await self.bot.send_message(
                             message.author,
                             self.json[message.server.id]['message'])
示例#6
0
    def is_sel_or_superior(self, obj):
        if isinstance(obj, discord.Message):
            user = obj.author
        elif isinstance(obj, discord.Member):
            user = obj
        elif isinstance(obj, discord.Role):
            pass
        else:
            raise TypeError('Seuls les messages, membres ou rôles peuvent être passés')

        server = obj.server
        cocap_role = settings.get_server_cocap(server)
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)
        sel_role = settings.get_server_sel(server)

        if isinstance(obj, discord.Role):
            return obj.name in [cocap_role, admin_role, mod_role, sel_role]

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=cocap_role):
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        elif discord.utils.get(user.roles, name=sel_role):
            return True
        else:
            return False
示例#7
0
    def is_mod_or_superior(self, obj):
        if isinstance(obj, discord.Message):
            user = obj.author
        elif isinstance(obj, discord.Member):
            user = obj
        elif isinstance(obj, discord.Role):
            pass
        else:
            raise TypeError('Only messages, members or roles may be passed')

        server = obj.server
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)

        if isinstance(obj, discord.Role):
            return obj.name in [admin_role, mod_role]

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        else:
            return False
示例#8
0
 def get_role(self, user: discord.Member, server: discord.Server):
     _msg = ""
     if user.id in self.bot.get_cog("Owner").global_ignores["blacklist"]:
         # Users who have been blacklisted via [p]blacklist add
         _msg += ":no_entry_sign: **Blacklisted**\n"
     if user.id == settings.owner:
         _msg += ":tools: **Bot Owner**\n"
     admin = False
     mod = False
     sadmin = settings.get_server_admin(server)
     smod = settings.get_server_mod(server)
     for i in user.roles:
         if i.name.lower() == sadmin.lower():
             admin = True
         elif i.name.lower() == smod.lower():
             mod = True
     if int(user.id) == int(server.owner.id):
         _msg += ":key: Server Owner"
     elif admin is True:
         _msg += ":hammer: Server Admin"
     elif mod is True:
         _msg += ":shield: Server Mod"
     else:
         _msg += ":bust_in_silhouette: Member"
     return _msg
示例#9
0
def authorized(message, authorized_roles=[]):
    if message.author.id == settings.owner:
        return True

    if message.server and message.server.owner.id == message.author.id:
        return True

    if message.channel.is_private:
        return False

    server = message.server

    admin_role = settings.get_server_admin(server).lower()
    mod_role = settings.get_server_mod(server).lower()

    for role in message.author.roles:
        role = role.name.lower()
        if role == admin_role:
            return True
        if role == mod_role:
            return True
        if role in authorized_roles:
            return True

    return False
示例#10
0
def mod_or_perms(ctx, **perms):
    try:
        server = ctx.message.server
        mod_role = settings.get_server_mod(server).lower()
        admin_role = settings.get_server_admin(server).lower()
        return checks.role_or_permissions(ctx, lambda r: r.name.lower() in (mod_role, admin_role), **perms)
    except:
        return False
示例#11
0
 def predicate(ctx):
     server = ctx.message.server
     sel_role = settings.get_server_sel(server).lower()
     mod_role = settings.get_server_mod(server).lower()
     admin_role = settings.get_server_admin(server).lower()
     cocap_role = settings.get_server_cocap(server).lower()
     return role_or_permissions(
         ctx, lambda r: r.name.lower() in
         (sel_role, mod_role, admin_role, cocap_role), **perms)
示例#12
0
def check_mod(ctx):
    if ctx.message.author.id == settings.owner:
        return True
    server = ctx.message.server
    mod_role = settings.get_server_mod(server).lower()
    admin_role = settings.get_server_admin(server).lower()
    author = ctx.message.author
    role = discord.utils.find(lambda r: r.name.lower() in (mod_role,admin_role), author.roles)
    return role is not None
示例#13
0
 def is_mod(self, user: discord.Member, server: discord.Server):
     if int(user.id) == int(server.owner.id):
         return True
     sadmin = settings.get_server_admin(server)
     smod = settings.get_server_mod(server)
     for i in user.roles:
         if i.name.lower() == sadmin.lower():
             return True
         elif i.name.lower() == smod.lower():
             return True
示例#14
0
    async def mentionmods(self, ctx):
        """
        mentions online mods and admins
        """
        server = ctx.message.server
        mod_role_name = settings.get_server_mod(server).lower() \
            if settings.get_server_mod(server) else None
        admin_role_name = settings.get_server_admin(server).lower() \
            if settings.get_server_admin(server) else None
        rolenames = [rn for rn in (mod_role_name, admin_role_name) if rn]
        roles = [r for r in server.roles
                 if r.name.lower() in rolenames]
        if len(roles) == 0:
            return
        mentions = [m.mention for m in server.members
                    if not set(m.roles).isdisjoint(roles)
                    and m.status == discord.Status.online]

        output = " ".join(mentions)

        for page in pagify(output):
            await self.bot.say(page)
示例#15
0
    async def setup(self, ctx):
        """Setup the channel and role for raid-protect v2.0"""
        server = ctx.message.server
        chrolename = "raid"
        try:
            role = self.find_role(server, chrolename)
            if role.name == chrolename:
                e = discord.Embed(title="Anti-Raid", description="Raid-protection is already set up. If you removed the"
                                                                 " channel and want to set Raid-protection up again, "
                                                                 "please remove the role **raid** in the Server Settings first!",
                                  colour=discord.Colour.red())
                await self.bot.say(embed=e)
                return
        except:
            covrole = await self.bot.create_role(server, name=chrolename)
            admin_role = discord.utils.get(server.roles, name=settings.get_server_admin(server))
            everyone_perms = discord.PermissionOverwrite(read_messages=False)
            insilenced_perms = discord.PermissionOverwrite(read_messages=True, send_messages=True)
            mod_admin_perms = discord.PermissionOverwrite(read_messages=True, send_messages=True,
                                                          manage_channel=True)
            chn = await self.bot.create_channel(
                server, chrolename,
                (server.default_role, everyone_perms),
                (covrole, insilenced_perms),
                (admin_role, mod_admin_perms))

            for role in ctx.message.server.roles:
                if "raid" in role.name:
                    for channelx in ctx.message.server.channels:
                        if "raid" in channelx.name:
                            for c in ctx.message.server.channels:
                                if c.name != chn.name:
                                    try:
                                        await self.bot.edit_channel_permissions(c, covrole, everyone_perms)
                                    except discord.errors.Forbidden:
                                        pass
            e = discord.Embed(title="Anti-Raid", description="Raid-protection has been set up!",
                              colour=discord.Colour.red())
            await self.bot.send_message(chn, embed=e)

            await asyncio.sleep(1)
            for c in server.channels:
                if c.name != chn.name:
                    try:
                        await self.bot.edit_channel_permissions(c, covrole, everyone_perms)
                    except discord.errors.Forbidden:
                        pass
            e2 = discord.Embed(description="Raid-protection is now active! Contact a Staff Member for"
                                           " help or wait till you get verified!", colour=discord.Colour.red())
            await self.bot.send_message(chn, embed=e2)
示例#16
0
    def immune_from_filter(self, message):
        user = message.author
        server = message.server
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        else:
            return False
示例#17
0
 def __init__(self, bot):
     self.bot = bot
     self.steamList = dataIO.load_json("data/steam/steam.json")
     self.rankList = dataIO.load_json("data/rank/rank.json")
     self.server = discord.utils.find(
         lambda m: m.id == '174382936877957120', self.bot.servers)
     self.admin_role = settings.get_server_admin(self.server)
     self.mod_role = settings.get_server_mod(self.server)
     self.allRanks = [
         "Unranked", "Bronze 1", "Bronze 2", "Bronze 3", "Silver 1",
         "Silver 2", "Silver 3", "Gold 1", "Gold 2", "Gold 3", "Platinum 1",
         "Platinum 2", "Platinum 3", "Diamond 1", "Diamond 2", "Diamond 3",
         "Champion 1", "Champion 2", "Champion 3", "Grand Champion"
     ]
示例#18
0
    def immune_from_filter(self, message):
        user = message.author
        server = message.server
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        else:
            return False
示例#19
0
    def immune_from_filter(self, message):
        """Tests message to see if it is exempt from filter. Taken from mod.py"""
        user = message.author
        server = message.server
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        else:
            return False
示例#20
0
    def immune_from_filter(self, message):
        """Tests message to see if it is exempt from filter. Taken from mod.py"""
        user = message.author
        server = message.server
        admin_role = settings.get_server_admin(server)
        mod_role = settings.get_server_mod(server)

        if user.id == settings.owner:
            return True
        elif discord.utils.get(user.roles, name=admin_role):
            return True
        elif discord.utils.get(user.roles, name=mod_role):
            return True
        else:
            return False
示例#21
0
 async def is_alone_or_admin(self, message): #Direct control. fix everything
     author = message.author
     server = message.server
     if not self.settings["QUEUE_MODE"]:
         return True
     elif author.id == bot_settings.owner:
         return True
     elif discord.utils.get(author.roles, name=bot_settings.get_server_admin(server)) is not None:
         return True
     elif discord.utils.get(author.roles, name=bot_settings.get_server_mod(server)) is not None:
         return True
     elif len(author.voice_channel.voice_members) in (1, 2):
         return True
     else:
         return False
示例#22
0
	async def spam(self, ctx, user : discord.Member):
		"""Sends 5 PMs to a user
		
		spam [user] - Bot will send 5 private messages to the specified  user (cannot spam bot or admins)."""
		msg = ''
		server = ctx.message.server
		admin_role = settings.get_server_admin(server)
		if user.id == self.bot.user.id:
			user = ctx.message.author
			msg = 'Haha, you cannot spam me!'
		elif discord.utils.get(user.roles, name=admin_role):
			user = ctx.message.author
			msg = 'Haha, you cannot spam an admin!'
		else:
			msg = 'Spam courtesy of {} :D'.format(ctx.message.author.mention)
		for x in range(0, 5):
			await self.bot.send_message(user, msg)
示例#23
0
    async def spam(self, ctx, user: discord.Member):
        """Sends 5 PMs to a user
		
		spam [user] - Bot will send 5 private messages to the specified  user (cannot spam bot or admins)."""
        msg = ''
        server = ctx.message.server
        admin_role = settings.get_server_admin(server)
        if user.id == self.bot.user.id:
            user = ctx.message.author
            msg = 'Haha, you cannot spam me!'
        elif discord.utils.get(user.roles, name=admin_role):
            user = ctx.message.author
            msg = 'Haha, you cannot spam an admin!'
        else:
            msg = 'Spam courtesy of {} :D'.format(ctx.message.author.mention)
        for x in range(0, 5):
            await self.bot.send_message(user, msg)
示例#24
0
    async def slow_check(self, message):
        storage = await self.get_storage(message.server)
        # Check if the user is a mod/admin/etc
        roles = [r.name for r in user.roles]
        bot_admin = settings.get_server_admin(message.server)
        bot_mod = settings.get_server_mod(message.server)
        if message.channel.id in self.json[
                message.server.id]['excluded_channels']:
            return
        elif user.id == settings.owner:
            return
        elif bot_admin in roles:
            return
        elif bot_mod in roles:
            return
        elif user.permissions_in(message.channel).manage_messages is True:
            return
        # Check if the channel is in slowmode
        slowed_channels = await storage.smembers('slowmode:channels')
        if message.channel.id not in slowed_channels:
            return
        # Grab the slowmode interval
        interval = await storage.get('slowmode:{}:interval'.format(
            message.channel.id))
        if not interval:
            return

        # If the user not in the slowed list
        # Add the user to the slowed list
        await storage.sadd('slowmode:{}:slowed'.format(message.channel.id),
                           message.author.id)
        # Check if user slowed
        slowed = await storage.get('slowmode:{}:slowed:{}'.format(
            message.channel.id, message.author.id)) is not None

        if slowed:
            await self.bot.delete_message(message)
        else:
            # Register a TTL key for the user
            await storage.set(
                'slowmode:{}:slowed:{}'.format(message.channel.id,
                                               message.author.id), interval)
            await storage.expire(
                'slowmode:{}:slowed:{}'.format(message.channel.id,
                                               message.author.id),
                int(interval))
示例#25
0
    async def _new_message(self, message):
        """Finds the message and checks it for regex"""
        user = message.author
        if message.server is None:
            return
        if message.server.id in self.json:

            if self.json[message.server.id]['toggle'] is True:

                roles = [r.name for r in user.roles]
                bot_admin = settings.get_server_admin(message.server)
                bot_mod = settings.get_server_mod(message.server)
                if message.channel.id in self.json[
                        message.server.id]['excluded_channels']:
                    return
                elif user.id == settings.owner:
                    return
                elif bot_admin in roles:
                    return
                elif bot_mod in roles:
                    return
                elif user.permissions_in(
                        message.channel).manage_messages is True:
                    return

                if self.json[message.server.id]['strict']:
                    for match in self.regex_url.finditer(message.content):
                        if self.emoji_string not in match.group(0):
                            asyncio.sleep(0.5)
                            await self.bot.delete_message(message)
                            if self.json[message.server.id]['dm'] is True:
                                await self.bot.send_message(
                                    message.author,
                                    self.json[message.server.id]['message'])
                            break
                elif self.regex.search(message.content) is not None:

                    asyncio.sleep(0.5)
                    await self.bot.delete_message(message)
                    if self.json[message.server.id]['dm'] is True:
                        await self.bot.send_message(
                            message.author,
                            self.json[message.server.id]['message'])
示例#26
0
    async def complexout(self, ctx, channel_id: str):
        """
        puts the output for the current server in another server.

        This takes a channel ID

        Be careful with managing this
        """

        server = ctx.message.server
        if server.id not in self.settings:
            self.initial_config(server.id)

        chan = discord.utils.get(self.bot.get_all_channels(), id=channel_id)

        if not (checks.is_owner_check(ctx)
                or checks.role_or_permissions(lambda r: r.name.lower(
                ) == settings.get_server_admin(chan.server).lower(),
                                              manage_server=True)):
            return await self.bot.say(
                "You don't have the right permissions in the destination serverto do that!"
            )

        if chan.type != discord.ChannelType.text:
            return await self.bot.say("That isn't a text channel")
        if chan.id in self.settings[server.id]['output']:
            return await self.bot.say("Channel already set as output")

        if self.settings[server.id]['multiout']:
            self.settings[server.id]['output'].append(chan.id)
            self.save_json()
            return await self.bot.say("Channel added to output list")
        else:
            self.settings[server.id]['output'] = [chan.id]
            self.save_json()
            return await self.bot.say("Channel set as output")
示例#27
0
 async def _new_message(self, message):
     """Finds the message and checks it for regex"""
     user = message.author
     if message.server is None:
         return
     if message.server.id in self.json:
         if self.json[message.server.id]['toggle'] is True:
             if self.regex.search(message.content) is not None or self.regex_discordme.search(message.content) is not None:
                 roles = [r.name for r in user.roles]
                 bot_admin = settings.get_server_admin(message.server)
                 bot_mod = settings.get_server_mod(message.server)
                 if user.id == settings.owner:
                     return
                 elif bot_admin in roles:
                     return
                 elif bot_mod in roles:
                     return
                 elif user.permissions_in(message.channel).manage_messages is True:
                     return
                 else:
                     asyncio.sleep(0.5)
                     await self.bot.delete_message(message)
                     if self.json[message.server.id]['dm'] is True:
                         await self.bot.send_message(message.author, self.json[message.server.id]['message'])
示例#28
0
 def predicate(ctx):
     server = ctx.message.server
     admin_role = settings.get_server_admin(server)
     return role_or_permissions(
         ctx, lambda r: r.name.lower() == admin_role.lower(), **perms)
示例#29
0
    async def on_member_join(self, member):
        if (member.server.id in self.settings) and not ("bots" in member.server.name.lower()):
            try:
                temp = self.settings[member.server.id]['joined']
            except KeyError:
                self.settings[member.server.id]['joined'] = 0
            try:
                self.settings[member.server.id]['joined'] += 1
                self.save_settings()
                if self.settings[member.server.id]['members'] != 0:
                    if (self.settings[member.server.id]['joined'] >= self.settings[member.server.id]['members']) and not (self.settings[member.server.id]['protected']):
                        self.settings[member.server.id]['protected'] = True
                        self.save_settings()
                        #for channel in member.server.channels:
                        #    if (channel.id == self.settings[member.server.id]['channel']) and (self.settings[member.server.id]['channel'] != None):
                        #        await self.bot.send_message(channel, "Raid protect has been turned on, more than {} people joined within 15 seconds.".format(self.settings[member.server.id]['members']))
                await asyncio.sleep(15)
                self.settings[member.server.id]['joined'] = 0
                self.save_settings()
            except KeyError:
                pass
            try:
                if self.settings[member.server.id]['protected']:
                    server = member.server
                    chrolename = "raid"
                    try:
                        role = self.find_role(server, chrolename)
                        if role.name == chrolename:
                            await self._auto_give(member)
                    except:
                        covrole = await self.bot.create_role(server, name=chrolename)
                        admin_role = discord.utils.get(server.roles, name=settings.get_server_admin(server))
                        everyone_perms = discord.PermissionOverwrite(read_messages=False)
                        insilenced_perms = discord.PermissionOverwrite(read_messages=True, send_messages=True)
                        mod_admin_perms = discord.PermissionOverwrite(read_messages=True, send_messages=True,
                                                                      manage_channel=True)
                        chn = await self.bot.create_channel(
                            server, chrolename,
                            (server.default_role, everyone_perms),
                            (covrole, insilenced_perms),
                            (admin_role, mod_admin_perms))

                        for role in member.server.roles:
                            if "raid" in role.name:
                                for channelx in member.server.channels:
                                    if "raid" in channelx.name:
                                        for c in member.server.channels:
                                            if c.name != chn.name:
                                                try:
                                                    await self.bot.edit_channel_permissions(c, covrole, everyone_perms)
                                                except discord.errors.Forbidden:
                                                    pass
                        e = discord.Embed(title="Anti-Raid", description="Raid-protection has been set up!",
                                          colour=discord.Colour.red())
                        await self.bot.send_message(chn, embed=e)
                        await asyncio.sleep(1)
                        for c in member.server.channels:
                            if c.name != chn.name:
                                try:
                                    await self.bot.edit_channel_permissions(c, covrole, everyone_perms)
                                except discord.errors.Forbidden:
                                    pass
                        e2 = discord.Embed(description="Raid-protection is now active! Contact a Staff Member for"
                                                      " help or wait till you get verified!", colour=discord.Colour.red())
                        await self.bot.send_message(chn, embed=e2)
                        await self._auto_give(member)
            except KeyError:
                return
示例#30
0
		async def crclip(self, ctx, filename=None, times=1,user:discord.User=None):
			'''
			syntax:
			filename must be a filename in my folder or filenames in my folder, separated by a /
			times must be a number or it will just do it once
			user must be a mention, id, username and it will find the voice channel in the server
			where the user is, and play it to them. specifying user only works for mods.

			'''
			# print('checking')
			# print(await ctx.invoke(self.perm_to_join_to_user))
			server = ctx.message.server
			mod_role = settings.get_server_mod(server)
			admin_role = settings.get_server_admin(server)
			mod_or_admin = False
			roles = list(map(lambda x: x.name, ctx.message.author.roles))
			mod_or_admin = admin_role in roles or mod_role in roles or checks.is_owner_check(ctx)
			if user == None or not mod_or_admin:
				user = ctx.message.author
			filenames = []
			if filename == None:
				await self.bot.say("You must specify a filename to play")
				return
			if '/' in filename:
				filenames = filename.split('/')
			else:
				filenames = [filename]
			for name in filenames:
				if name + self.exten not in os.listdir(AUDIOPATH) and name + self.exten not in os.listdir(TTSPATH):
					await self.bot.say("The file, `{}` is not saved in the audio folder.".format(name+self.exten))
					return
			try:
				client = await self.connect_with_user(ctx,user)
			except UserNotConnected as e:
				await self.bot.say(e.msg)
				return
			filenames = list(map(lambda filename:os.path.join(AUDIOPATH if filename +self.exten in os.listdir(AUDIOPATH) else TTSPATH, filename + self.exten), filenames))
			try:
				times = int(times)
			except:
				times = 1
			if times>5:
				times=5
			elif times<1:
				times=1
			self.is_playing = dataIO.load_json(SETTINGS_JSON)['playing']
			if self.is_playing:
				await self.bot.say("You may not play anything if it is already playing something.")
				return

			self.set_play(True)
			dataIO.save_json(SETTINGS_JSON, self.settings)
			n = 0
			if times==1:
				for name in filenames:
					if n>0:
						while player.is_playing():
							await asyncio.sleep(.2)
					player = client.create_ffmpeg_player(name)
					player.start()
					n += 1
			else:
				
				for x in range(times):
					for name in filenames:
						if n>0:
							while player.is_playing():
								await asyncio.sleep(.2)
						player = client.create_ffmpeg_player(name)
						player.start()
						n += 1

			while player.is_playing():
				await asyncio.sleep(.2)
			self.set_play(False)
示例#31
0
文件: checks.py 项目: b0r3d0/kitty
 def predicate(ctx):
     server = ctx.message.server
     admin_role = settings.get_server_admin(server)
     return role_or_permissions(ctx, lambda r: r.name.lower() == admin_role.lower(), **perms)
示例#32
0
文件: checks.py 项目: b0r3d0/kitty
 def predicate(ctx):
     server = ctx.message.server
     recruiter_role = settings.get_server_recruiter(server).lower()
     mod_role = settings.get_server_mod(server).lower()
     admin_role = settings.get_server_admin(server).lower()
     return role_or_permissions(ctx, lambda r: r.name.lower() in (recruiter_role,mod_role,admin_role), **perms)