Exemple #1
0
 async def quoteadd(self, ctx, target: discord.User, *, text: str):
     """Add a quote.
     Usage: quoteadd [member] [text here]"""
     if len(text) > 360:
         await self.bot.reply('your text is too long!')
         return
     if target == self.bot.user:
         if not check_perms(ctx, ('bot_owner',)):
             await self.bot.reply('you can\'t add a quote as me!')
             return
     fmt_time = [int(i) for i in time.strftime("%m/%d/%Y").split('/')]
     q_template = {
         'id': 0,
         'quote': 'Say-whaaaa?',
         'author': ctx.message.author.display_name,
         'author_ids': [''],
         'date': fmt_time
     }
     mauthor = target
     q_template['quote'] = text.replace('\n', ' ').replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
     q_template['author'] = mauthor.display_name
     if mauthor.display_name != mauthor.name:
         q_template['author'] += ' (' + mauthor.name + ')'
     q_template['author_ids'] = [mauthor.id, ctx.message.author.id]
     q_template['id'] = len(self.bot.store['quotes']) # +1 for next id, but len() counts from 1
     self.bot.store['quotes'].append(q_template)
     await self.bot.reply(f'you added quote **#{q_template["id"] + 1}**!')
Exemple #2
0
 async def admintest(self, ctx):
     """Check to see if you're registered as a bot admin.
     Usage: admintest'"""
     tmp = check_perms(ctx, ('bot_admin', ))
     if tmp:
         await ctx.send(ctx.mention + ' You are a bot admin! :smiley:')
     else:
         await ctx.send(ctx.mention +
                        ' You are not a bot admin! :slight_frown:')
Exemple #3
0
 async def quotedel(self, ctx, qindex: int):
     """Delete an existing quote.
     Usage: quotedel [quote number]"""
     if qindex < 0:
         await self.bot.reply('there aren\'t negative quotes!')
         return
     try:
         q_target = self.bot.store['quotes'][qindex - 1]
     except IndexError:
         await self.bot.reply(f'quote **#{qindex}** doesn\'t already exist!')
         return
     mauthor = ctx.message.author
     _pcheck = check_perms(ctx, ('bot_admin',))
     if (mauthor.id == q_target['author_ids'][0]) or (_pcheck):
         del self.bot.store['quotes'][qindex - 1]
         await self.bot.reply(f'you deleted quote **#{qindex}**!')
     else:
         await self.bot.reply(f'you can\'t delete quote **#{qindex}** because you didn\'t write it. Sorry!')
Exemple #4
0
 async def quotemod(self, ctx, qindex: int, *, text: str):
     """Edit an existing quote.
     Usage: quotemod [quote number] [new text here]"""
     if len(text) > 360:
         await self.bot.reply('your text is too long!')
         return
     if qindex < 0:
         await self.bot.reply('there aren\'t negative quotes!')
         return
     try:
         q_template = self.bot.store['quotes'][qindex - 1]
     except IndexError:
         await self.bot.reply('that quote doesn\'t already exist!')
         return
     if not check_perms(ctx, ('bot_admin',)):
         if ctx.message.author.id not in q_template['author_ids']:
             await self.bot.reply('you need more permissions!')
             return
     q_template['quote'] = text.replace('\n', ' ').replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
     self.bot.store['quotes'][qindex - 1] = q_template
     await self.bot.reply(f'you edited quote **#{qindex}**!')
Exemple #5
0
 async def addadmin(self, ctx, *rrtarget: str):
     """Add a user to the bot admin list.
     Usage: addadmin [user]"""
     tmp = check_perms(ctx, ('bot_admin', ))
     if not rrtarget:
         await self.bot.say(
             '**You need to specify a name, nickname, name#0000, mention, or ID!**'
         )
         return
     rtarget = ' '.join(rrtarget)
     try:
         _target = ctx.message.server.get_member_named(rtarget)
     except AttributeError:
         _target = None
     if _target:
         target = _target.id
     elif len(rtarget) == 18:
         target = rrtarget[0]
     elif ctx.message.mentions:
         target = ctx.message.mentions[0].id
     else:
         await self.bot.say(
             '**Invalid name! Name, nickname, name#0000, mention, or ID work.**'
         )
         return
     if tmp:
         aentry = target
         if aentry not in self.bot.store['bot_admins']:
             self.bot.store['bot_admins'].append(aentry)
             await self.bot.say(
                 'The user specified has successfully been added to the bot admin list!'
             )
         else:
             await self.bot.say('The user specified is already a bot admin!'
                                )
     else:
         await self.bot.say(
             ctx.message.author.mention +
             ' You are not a bot admin, so you may not add others as admins!'
         )
Exemple #6
0
 async def rmadmin(self, ctx, *rrtarget: str):
     """Remove a user from the bot admin list.
     Usage: rmadmin [user]"""
     tmp = check_perms(ctx, ('bot_admin', ))
     if not rrtarget:
         await self.bot.say(
             '**You need to specify a name, nickname, name#discriminator, or ID!**'
         )
         return
     rtarget = ' '.join(rrtarget)
     try:
         _target = ctx.message.server.get_member_named(rtarget)
     except AttributeError:
         _target = None
     if _target:
         target = _target.id
     elif len(rtarget) in [15, 16, 17, 18, 19, 20]:
         target = rrtarget[0]
     else:
         await self.bot.say(
             '**Invalid name! Name, nickname, name#discriminator, or ID work.**'
         )
         return
     if tmp:
         aentry = target
         try:
             self.bot.store['bot_admins'].remove(aentry)
         except ValueError:
             await self.bot.say('The user specified is not a bot admin!')
         else:
             await self.bot.say(
                 'The user specified has successfully been demoted!')
     else:
         await self.bot.say(
             ctx.message.author.mention +
             ' You are not a bot admin, so you may not demote other admins!'
         )
Exemple #7
0
 async def user(self, ctx, *users: str):
     """Get tons of info on an user or some users.
     Spaces, multiuser, and cross-server IDs work.
     Usage: user {user(s)}"""
     targets = []
     s = ctx.message.server
     if users: # huge complicated mess for spaces,
               # multiuser, nicknames, mentions, IDs,
               # names, and more in one go.
         members = {}
         for i in getattr(s, 'members', []):
             members[i.mention] = i
             members[i.id] = i
             members[i.display_name] = i
             members[i.name] = i
             members[str(i)] = i
         for i in users:
             try:
                 member = s.get_member(i)
             except AttributeError:
                 try:
                     member = await self.bot.get_user_info(i)
                 except discord.HTTPException:
                     member = None
             if member:
                 targets.append(member)
             else:
                 try:
                     member = await self.bot.get_user_info(i)
                 except discord.HTTPException:
                     member = None
                 if member:
                     targets.append(member)
         names = []
         _i = 0
         while _i < len(users):
             names.append(users[_i])
             with suppress(KeyError):
                 if ' '.join(names) in members:
                     targets.append(members[' '.join(names)])
                     names = []
                 elif _i + 1 == len(users):
                     targets.append(members[users[0]])
                     _i = -1
                     users = users[1:]
                     names = []
             _i += 1
         if not targets:
             await self.bot.say('**No matching users, try again! Name, nickname, name#0000 (discriminator), or ID work. Spaces do, too!**')
             return
     else:
         targets.append(ctx.message.author)
     targets = list(OrderedDict.fromkeys(targets))
     for target in targets:
         au = target.avatar_url
         avatar_link = (au if au else target.default_avatar_url)
         d_name = target.display_name
         try:
             t_roles = target.roles
         except AttributeError:
             t_roles = []
         try:
             t_game = target.game
         except AttributeError:
             t_game = None
         b_roles = []
         c_srv = False
         c_sown = False
         try:
             tg_ctx = FakeContextMember(FakeMessageMember(target), self.bot)
         except AttributeError:
             tg_ctx = None
         else:
             c_srv = check_perms(tg_ctx, ('manage_server',))
             c_sown = check_perms(tg_ctx, ('server_owner',))
         c_own = target.id == self.bot.owner_user.id
         c_adm = target.id in self.bot.store['bot_admins']
         is_server = isinstance(target, discord.Member)
         if c_own:
             b_roles.append('Bot Owner')
         if c_adm:
             b_roles.append('Bot Admin')
         if c_srv:
             b_roles.append('Server Admin')
         with suppress(ValueError, AttributeError):
             t_roles.remove(target.server.default_role)
         r_embed = discord.Embed(color=int('0x%06X' % random.randint(0, 256**3-1), 16))
         r_embed.set_author(name=str(target), icon_url=avatar_link, url=avatar_link)
         r_embed.set_thumbnail(url=avatar_link) #top right
         r_embed.set_footer(text=str(target), icon_url=avatar_link)
         r_embed.add_field(name='Nickname', value=('No nickname set 😦' if d_name == target.name else d_name))
         r_embed.add_field(name='User ID', value=target.id)
         r_embed.add_field(name='Creation Time', value=target.created_at.strftime(absfmt))
         r_embed.add_field(name='Server Join Time', value=target.joined_at.strftime(absfmt) if is_server else 'Couldn\'t fetch')
         r_embed.add_field(name='Server Roles', value=', '.join([str(i) for i in t_roles]) if t_roles else 'User has no server roles 😦')
         r_embed.add_field(name='Bot Roles', value=', '.join(b_roles) if b_roles else 'User has no bot roles 😦')
         r_embed.add_field(name='Status', value=status_map[str(target.status)] if is_server else 'Couldn\'t fetch')
         try:
             r_embed.add_field(name='Currently Playing', value=(str(t_game) if t_game else 'Nothing 😦'))
         except TypeError:
             r_embed.add_field(name='Currently Playing', value='Nothing 😦')
         await self.bot.say(embed=r_embed)