Пример #1
0
async def itemstatistics(cmd: SigmaCommand, message: discord.Message,
                         args: list):
    item_core = await get_item_core(cmd.db)
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    all_stats = await cmd.db[cmd.db.db_nam].ItemStatistics.find_one(
        {'UserID': target.id}) or {}
    if '_id' in all_stats:
        all_stats.pop('_id')
        all_stats.pop('UserID')
    all_stats = [[x, all_stats.get(x)] for x in all_stats.keys()]
    mem_count = len(all_stats)
    all_stats = sorted(all_stats, key=lambda k: k[1], reverse=True)
    page = args[0] if args else 1
    all_stats, page = paginate(all_stats, page)
    total_count = len([i for i in item_core.all_items if i.rarity != 0])
    listing = []
    for stat in all_stats:
        item_o = item_core.get_item_by_file_id(stat[0])
        if item_o.rarity != 0:
            amount = stat[1]
            listing.append([item_o.name, amount])
    out_table = boop(listing, ['Item', 'Count'])
    response = discord.Embed(color=0xc16a4f)
    response.set_author(name=f'{target.name}\'s Item Statistics',
                        icon_url=user_avatar(target))
    response.description = f'```hs\n{out_table}\n```'
    response.set_footer(
        text=
        f'[Page {page}] {target.name} has found {mem_count} out of {total_count} items.'
    )
    await message.channel.send(embed=response)
async def listinactivewarnings(cmd: SigmaCommand, message: discord.Message, args: list):
    if message.author == message.guild.owner:
        target = message.mentions[0] if message.mentions else message.author
        if target:
            lookup = {'guild': message.guild.id, 'target.id': target.id, 'warning.active': False}
            warnings = await cmd.db[cmd.db.db_nam].Warnings.find(lookup).to_list(None)
            if warnings:
                warn_list = []
                for warning in warnings:
                    warn_id = warning.get('warning').get('id')
                    mod_id = warning.get('moderator').get('id')
                    moderator = discord.utils.find(lambda x: x.id == mod_id, cmd.bot.get_all_members())
                    if moderator:
                        moderator = moderator.name
                    else:
                        moderator = warning.get('moderator').get('name')
                    warn_time = arrow.get(warning.get('warning').get('timestamp')).format('DD. MMM. YYYY. HH:mm')
                    warn_list.append(f'`{warn_id}` by **{moderator}** on {warn_time}.')
                page = args[1] if len(args) > 1 else 1
                warn_list, page = paginate(warn_list, page, 5)
                start_range, end_range = (page - 1) * 5, page * 5
                warn_list = '\n'.join(warn_list)
                ender = 's' if len(warnings) > 1 else ''
                start = f'{target.name} has' if target.id != message.author.id else 'You have'
                response = discord.Embed(color=0xFFCC4D)
                response.add_field(name=f'тЪа {start} {len(warnings)} inactive warning{ender}.', value=warn_list)
                response.set_footer(text=f'Showing warns {start_range}-{end_range} out of {len(warnings)}.')
            else:
                start = f'{target.name} doesn\'t' if target.id != message.author.id else 'You don\'t'
                response = discord.Embed(color=0x55acee, title=f'ЁЯТа {start} have any inactive warnings.')
        else:
            response = discord.Embed(color=0xBE1931, title=f'тЭЧ No user targeted.')
    else:
        response = permission_denied('Server Owner')
    await message.channel.send(embed=response)
Пример #3
0
async def ingame(cmd: SigmaCommand, message: discord.Message, args: list):
    response = discord.Embed(color=0x1ABC9C)
    games, online, playing = make_games_dict(message.guild)
    sorted_games = sorted(games.items(),
                          key=operator.itemgetter(1),
                          reverse=True)
    page = args[0] if args else 1
    game_list, page = paginate(sorted_games, page)
    start_range = (page - 1) * 10
    out_table_list = []
    game_count = len(sorted_games)
    index = start_range
    for key, value in game_list:
        index += 1
        if len(key) > 32:
            key = key[:32] + '...'
        out_table_list.append([
            str(index), key, value,
            str(value / playing * 100).split('.')[0] + '%'
        ])
    output = boop(out_table_list)
    general_stats_list = [['Online', online], ['In-Game', playing],
                          ['Unique Games', game_count]]
    out_block = f'```hs\n{boop(general_stats_list)}\n```'
    response.add_field(name='👾 Current Gaming Statistics on ' +
                       message.guild.name,
                       value=out_block,
                       inline=False)
    response.add_field(name=f'🎮 By Game on Page {page}',
                       value=f'```haskell\n{output}\n```',
                       inline=False)
    await message.channel.send(embed=response)
Пример #4
0
async def disabledcommands(cmd: SigmaCommand, message: discord.Message,
                           args: list):
    page = args[0] if args else 1
    perms = await get_all_perms(cmd.db, message)
    disabled_commands = perms['disabled_commands']
    overridden_commands = perms['command_exceptions']
    disabled_list = []
    for dcmd_name in disabled_commands:
        if dcmd_name in cmd.bot.modules.categories:
            if dcmd_name in overridden_commands:
                dcmd_name += '\*'
            disabled_list.append(dcmd_name)
    if disabled_list:
        disabled_count = len(disabled_list)
        disabled_list, page_num = paginate(disabled_list, page, 50)
        title = f'{message.guild.name} Disabled Commands'
        info_text = f'[Page {page_num}] Showing {len(disabled_list)} out of {disabled_count} disabled commands.'
        response = discord.Embed(
            color=await get_image_colors(message.guild.icon_url))
        response.set_author(name=title, icon_url=message.guild.icon_url)
        response.description = ', '.join(disabled_list)
        response.set_footer(text=info_text)
    else:
        response = discord.Embed(color=0x696969,
                                 title=f'🔍 No disabled commands found.')
    await message.channel.send(embed=response)
async def listrolegroups(cmd: SigmaCommand, message: discord.Message,
                         args: list):
    role_groups = await cmd.db.get_guild_settings(message.guild.id,
                                                  'role_groups') or {}
    group_list = list(role_groups.keys())
    if role_groups:
        group_count = len(group_list)
        page = args[0] if args else 1
        group_list, page = paginate(group_list, page)
        ender = 's' if len(group_list) > 1 else ''
        summary = f'Showing **{len(group_list)}** group{ender} from Page **#{page}**.'
        summary += f'\n{message.guild.name} has **{group_count}** role group{ender}.'
        rl_out = ''
        group_list = sorted(group_list)
        for rl in group_list:
            rl_out += f'\n`{rl}`: {len(list(role_groups.get(rl)))} Roles'
        response = discord.Embed(
            color=await get_image_colors(message.guild.icon_url))
        response.set_author(name=message.guild.name,
                            icon_url=message.guild.icon_url)
        response.add_field(name=f'Role Group Summary',
                           value=summary,
                           inline=False)
        response.add_field(name=f'List of Role Groups',
                           value=f'{rl_out}',
                           inline=False)
        response.set_footer(
            text=
            f'You can see all roles in a group using the {cmd.bot.cfg.pref.prefix}verg command.'
        )
    else:
        response = discord.Embed(
            color=0x696969,
            title=f'🔍 {message.guild.name} has no role groups.')
    await message.channel.send(embed=response)
Пример #6
0
async def decaying(cmd: SigmaCommand, message: discord.Message, args: list):
    page_num = args[0] if args else 1
    decaying_channels = await cmd.db.get_guild_settings(
        message.guild.id, 'DecayingChannels') or []
    if decaying_channels:
        decaying_count = len(decaying_channels)
        decaying_timers = await cmd.db.get_guild_settings(
            message.guild.id, 'DecayingTimers') or {}
        decaying_channels, page = paginate(decaying_channels, page_num)
        decay_names = []
        decay_timers = []
        for decaying_channel in decaying_channels:
            decchn = discord.utils.find(lambda c: c.id == decaying_channel,
                                        message.guild.channels)
            decchn = f'#{decchn.name}' if decchn else str(decaying_channel)
            dectmr = str(
                datetime.timedelta(
                    seconds=decaying_timers.get(str(decaying_channel))))
            decay_names.append(decchn)
            decay_timers.append(dectmr)
        title = f'{message.guild.name} Decaying Channels'
        info_text = f'[Page {page_num}] Showing {len(decaying_channels)} out of {decaying_count} decaying channels.'
        response = discord.Embed(
            color=await get_image_colors(message.guild.icon_url))
        response.add_field(name='Channels', value='\n'.join(decay_names))
        response.add_field(name='Timers', value='\n'.join(decay_timers))
        response.set_author(name=title, icon_url=message.guild.icon_url)
        response.set_footer(text=info_text)
    else:
        response = discord.Embed(color=0x696969,
                                 title=f'🔍 No decaying channels found.')
    await message.channel.send(embed=response)
Пример #7
0
async def recipes(cmd: SigmaCommand, message: discord.Message, args: list):
    recipe_core = await get_recipe_core(cmd.db)
    recipe_list = sorted(recipe_core.recipes, key=lambda x: x.name)
    page = args[0] if args else 1
    sales_data, page = paginate(recipe_list, page)
    start_range, end_range = (page - 1) * 10, page * 10
    recipe_look = secrets.choice(recipe_core.recipes)
    recipe_icon = recipe_look.icon
    recipe_color = recipe_look.color
    recipe_boop_head = ['Name', 'Type', 'Value', 'Ingr.']
    recipe_boop_list = []
    stats_text = f'Showing recipes: {start_range}-{end_range}.'
    stats_text += f'\nThere is a total of {len(recipe_core.recipes)} recipes.'
    if sales_data:
        for recipe in sales_data:
            req_satisfied = await check_requirements(cmd, message, recipe)
            req_needed = len(recipe.ingredients)
            req_reqs = f'{req_satisfied}/{req_needed}'
            recipe_boop_list.append(
                [recipe.name, recipe.type, recipe.value, req_reqs])
        recipe_table = boop(recipe_boop_list, recipe_boop_head)
        response = discord.Embed(color=recipe_color)
        response.add_field(name=f'{recipe_icon} Recipe Stats',
                           value=f'```py\n{stats_text}\n```',
                           inline=False)
        response.add_field(name=f'📰 Recipes On Page {page}',
                           value=f'```hs\n{recipe_table}\n```')
    else:
        response = discord.Embed(color=0x696969,
                                 title=f'🔍 This page is empty.')
    await message.channel.send(embed=response)
Пример #8
0
async def liststatuses(cmd: SigmaCommand, message: discord.Message,
                       args: list):
    status_data = await cmd.db[cmd.db.db_nam].StatusFiles.find({}
                                                               ).to_list(None)
    if status_data:
        status_list = [[s['id'], s['text']] for s in status_data]
        status_list = sorted(status_list, key=lambda x: x[1])
        total_status = len(status_list)
        page = args[0] if args else 1
        status_list, page = paginate(status_list, page)
        status_block = boop(status_list, ['ID', 'Text'])
        response = discord.Embed(
            color=await get_image_colors(cmd.bot.user.avatar_url))
        response.set_author(
            name=f'{cmd.bot.user.name}\'s Status Rotation Items',
            icon_url=user_avatar(cmd.bot.user))
        response.add_field(
            name='Info',
            value=
            f'Showing {len(status_list)} items out of {total_status} on page {page}.'
        )
        response.add_field(name="List",
                           value=f'```\n{status_block}\n```',
                           inline=False)
    else:
        response = discord.Embed(color=0x696969, title='🔍 No statuses found.')
    await message.channel.send(embed=response)
Пример #9
0
async def responders(cmd: SigmaCommand, message: discord.Message, args: list):
    responder_files = await cmd.db.get_guild_settings(message.guild.id,
                                                      'ResponderTriggers')
    if responder_files:
        responder_list = sorted(list(responder_files.keys()))
        resp_count = len(responder_list)
        page = args[0] if args else 1
        triggers, page = paginate(responder_list, page)
        start_range = (page - 1) * 10
        if triggers:
            ender = 's' if resp_count > 1 else ''
            summary = f'Showing **{len(triggers)}** trigger{ender} from Page **#{page}**.'
            summary += f'\n{message.guild.name} has **{resp_count}** responder trigger{ender}.'
            loop_index = start_range
            trg_list_lines = []
            for key in triggers:
                loop_index += 1
                list_line = f'**{loop_index}**: {key}'
                trg_list_lines.append(list_line)
            trg_list = '\n'.join(trg_list_lines)
            srv_color = await get_image_colors(message.guild.icon_url)
            response = discord.Embed(color=srv_color)
            response.set_author(name='Automatic Responder Triggers',
                                icon_url=message.guild.icon_url)
            response.add_field(name='Summary', value=summary, inline=False)
            response.add_field(name='Trigger List',
                               value=trg_list,
                               inline=False)
        else:
            response = discord.Embed(color=0xBE1931,
                                     title='❗ This page is empty.')
    else:
        response = discord.Embed(
            color=0xBE1931, title='❗ This server has no responder triggers.')
    await message.channel.send(embed=response)
Пример #10
0
async def listselfroles(cmd: SigmaCommand, message: discord.Message, args: list):
    self_roles = await cmd.db.get_guild_settings(message.guild.id, 'SelfRoles')
    if self_roles is None:
        self_roles = []
    role_list = []
    for srv_role in message.guild.roles:
        for role in self_roles:
            if role == srv_role.id:
                role_list.append(srv_role.name)
    if not role_list:
        response = discord.Embed(color=0x3B88C3, title='ℹ No self assignable roles set.')
    else:
        role_count = len(role_list)
        role_list = sorted(role_list)
        page = args[0] if args else 1
        role_list, page = paginate(role_list, page)
        ender = 's' if role_count > 1 else ''
        summary = f'Showing **{len(role_list)}** role{ender} from Page **#{page}**.'
        summary += f'\n{message.guild.name} has **{role_count}** self assignable role{ender}.'
        rl_out = ''
        for role in role_list:
            rl_out += '\n- ' + role
        response = discord.Embed(color=await get_image_colors(message.guild.icon_url))
        response.set_author(name=message.guild.name, icon_url=message.guild.icon_url)
        response.add_field(name=f'Self Assignable Role Stats', value=summary, inline=False)
        response.add_field(name=f'List of Self Assignable Roles', value=f'{rl_out}', inline=False)
    await message.channel.send(embed=response)
Пример #11
0
async def permittedchannels(cmd: SigmaCommand, message: discord.Message,
                            args: list):
    has_args = False if not args else False if ':' not in args[-1] else True
    page_num = args[0] if args else 1
    if has_args:
        modes = {
            'c':
            ('Command', 'CommandExceptions', cmd.bot.modules.commands, True),
            'm':
            ('Module', 'ModuleExceptions', cmd.bot.modules.categories, False)
        }
        perms = await get_all_perms(cmd.db, message)
        perm_mode, node_name = [piece.lower() for piece in args[-1].split(':')]
        mode_vars = modes.get(perm_mode)
        if mode_vars:
            overridden_channels = []
            mode_name, exception_group, check_group, check_alts = mode_vars
            if check_alts:
                if node_name in cmd.bot.modules.alts:
                    node_name = cmd.bot.modules.alts[node_name]
            if node_name in check_group:
                exceptions = perms.get(exception_group,
                                       {}).get(node_name,
                                               {}).get('Channels', [])
                for exc_chn_id in exceptions:
                    exc_chn = discord.utils.find(lambda c: c.id == exc_chn_id,
                                                 message.guild.channels)
                    exc_chn_name = f'#{exc_chn.name}' if exc_chn else str(
                        exc_chn_id)
                    overridden_channels.append(exc_chn_name)
                if overridden_channels:
                    total_overrides = len(overridden_channels)
                    overrides, page = paginate(overridden_channels, page_num,
                                               50)
                    title = f'{message.guild.name} {node_name.upper()} Channel Overrides'
                    info_text = f'[Page {page}] Showing {len(overrides)} out of {total_overrides} disabled modules.'
                    response = discord.Embed(
                        color=await get_image_colors(message.guild.icon_url))
                    response.set_author(name=title,
                                        icon_url=message.guild.icon_url)
                    response.description = ', '.join(overrides)
                    response.set_footer(text=info_text)
                else:
                    response = discord.Embed(
                        color=0x696969,
                        title=f'🔍 No overridden channels found for {node_name}.'
                    )
            else:
                response = discord.Embed(
                    color=0x696969,
                    title=f'🔍 No {node_name} {mode_name.lower()} found.')
        else:
            response = discord.Embed(
                color=0xBE1931,
                title='❗ Unrecognized lookup mode, see usage example.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
Пример #12
0
async def inventory(cmd: SigmaCommand, message: discord.Message, args: list):
    item_core = await get_item_core(cmd.db)
    reci_core = await get_recipe_core(cmd.db)
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    upgrade_file = await cmd.db[cmd.db.db_nam].Upgrades.find_one(
        {'user_id': target.id}) or {}
    storage = upgrade_file.get('storage', 0)
    inv_limit = 64 + (8 * storage)
    inv = await cmd.db.get_inventory(target)
    total_inv = len(inv)
    item_o_list = []
    item_filter = get_filter(args)
    for item in inv:
        item_o = item_core.get_item_by_file_id(item['item_file_id'])
        add = item_belongs(item_filter, item_o) if item_filter else True
        if add:
            item_o_list.append(item_o)
    item_o_list = sorted(item_o_list, key=attrgetter('value'), reverse=True)
    item_o_list = sorted(item_o_list, key=attrgetter('name'), reverse=False)
    item_o_list = sorted(item_o_list, key=attrgetter('rarity'), reverse=True)
    page = args[0] if args else 1
    inv, page = paginate(item_o_list, page)
    start_range, end_range = (page - 1) * 10, page * 10
    if inv:
        all_reci = reci_core.recipes
        headers = ['Type', 'Item', 'Value', 'Rarity']
        to_format = []
        total_value = 0
        for item_o_item in inv:
            in_rec = '*' if is_ingredient(all_reci, item_o_item) else ''
            to_format.append([
                item_o_item.type, f'{item_o_item.name}{in_rec}',
                f'{item_o_item.value}', f'{item_o_item.rarity_name.title()}'
            ])
        for item_o_item in item_o_list:
            total_value += item_o_item.value
        output = boop(to_format, column_names=headers)
        response = discord.Embed(color=0xc16a4f)
        inv_text = f'Showing items {start_range}-{end_range}.'
        pronouns = ['You', 'your'
                    ] if target.id == message.author.id else ['They', 'their']
        inv_text += f'\n{pronouns[0]} have {total_inv}/{inv_limit} items in {pronouns[1]} inventory.'
        inv_text += f'\nTotal value of {pronouns[1]} inventory is {total_value} {cmd.bot.cfg.pref.currency}.'
        response.add_field(name='📦 Inventory Stats',
                           value=f'```py\n{inv_text}\n```')
        response.add_field(name=f'📋 Items Currently On Page {page}',
                           value=f'```hs\n{output}\n```',
                           inline=False)
    else:
        response = discord.Embed(color=0xc6e4b5, title='💸 Totally empty...')
    response.set_author(name=f'{target.name}#{target.discriminator}',
                        icon_url=user_avatar(target))
    await message.channel.send(embed=response)
Пример #13
0
 def test_page(self):
     assert paginate([], 0) == ([], 1)
     assert paginate([], 1) == ([], 1)
     assert paginate([], 2) == ([], 1)
     assert paginate([], "0") == ([], 1)
     assert paginate([], "1") == ([], 1)
     assert paginate([], "2") == ([], 1)
     assert paginate([], None) == ([], 1)
Пример #14
0
async def allitems(cmd: SigmaCommand, message: discord.Message, args: list):
    item_core = await get_item_core(cmd.db)
    reci_core = await get_recipe_core(cmd.db)
    item_o_list = item_core.all_items
    special = False
    if args:
        types = ['animals', 'animal', 'plants', 'plant', 'fish']
        selection = args[0].lower()
        if selection in types:
            sort = selection[:-1] if selection.endswith('s') else selection
            item_o_list = [
                i for i in item_core.all_items if i.type == sort.title()
            ]
            special = True
    item_o_list = sorted(item_o_list, key=attrgetter('value'), reverse=True)
    item_o_list = sorted(item_o_list, key=attrgetter('name'), reverse=False)
    item_o_list = sorted(item_o_list, key=attrgetter('rarity'), reverse=True)
    if special:
        page = args[1] if len(args) > 1 else 1
    else:
        page = args[0] if args else 1
    inv, page = paginate(item_o_list, page)
    start_range, end_range = (page - 1) * 10, page * 10
    if inv:
        all_reci = reci_core.recipes
        headers = ['Type', 'Item', 'Value', 'Rarity']
        to_format = []
        total_value = 0
        for item_o_item in inv:
            in_rec = '*' if is_ingredient(all_reci, item_o_item) else ''
            to_format.append([
                item_o_item.type, f'{item_o_item.name}{in_rec}',
                f'{item_o_item.value}', f'{item_o_item.rarity_name.title()}'
            ])
        for item_o_item in item_o_list:
            total_value += item_o_item.value
        output = boop(to_format, column_names=headers)
        response = discord.Embed(color=0xc16a4f)
        response.set_author(name=f'{cmd.bot.user.name}',
                            icon_url=user_avatar(cmd.bot.user))
        inv_text = f'Showing items {start_range}-{end_range} out of {len(item_o_list)}.'
        inv_text += f'\nThe total value of this pool is {total_value} {cmd.bot.cfg.pref.currency}.'
        response.add_field(name='📦 Item Pool Stats',
                           value=f'```py\n{inv_text}\n```')
        response.add_field(name=f'📋 Items Currently On Page {page}',
                           value=f'```hs\n{output}\n```',
                           inline=False)
    else:
        response = discord.Embed(color=0xBE1931,
                                 title=f'❗ Could not retrieve Item Core data.')
    await message.channel.send(embed=response)
Пример #15
0
async def spouses(cmd: SigmaCommand, message: discord.Message, args: list):
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    profile = await cmd.db[cmd.db.db_nam].Profiles.find_one(
        {'user_id': target.id}) or {}
    splist = profile.get('spouses', [])
    spcount = len(splist)
    page = args[0] if args else 1
    splist, page = paginate(splist, page, 5)
    starter = 'You are' if target.id == message.author.id else f'{target.name} is'
    mid = 'have' if target.id == message.author.id else 'has'
    if splist:
        spdata = []
        all_members = cmd.bot.get_all_members()
        for sp in splist:
            spmemb = discord.utils.find(lambda m: m.id == sp.get('user_id'),
                                        all_members)
            spmemb = spmemb.name if spmemb else sp.get('user_id')
            sp_profile = await cmd.db[cmd.db.db_nam].Profiles.find_one(
                {'user_id': sp.get('user_id')}) or {}
            sp_spouses = sp_profile.get('spouses') or []
            sp_spouse_ids = [s.get('user_id') for s in sp_spouses]
            sp_status = 'Married' if target.id in sp_spouse_ids else 'Proposed'
            spdata.append([
                spmemb, sp_status,
                arrow.get(sp.get('time')).humanize().title()
            ])
        spbody = boop(spdata, ['Name', 'Status', 'Since'])
        upgrades = await cmd.db[cmd.db.db_nam].Upgrades.find_one(
            {'user_id': target.id}) or {}
        limit = 10 + (upgrades.get('harem') or 0)
        stats = f'[Page {page}] {target.name}\'s harem has {spcount}/{limit} people in it.'
        response = discord.Embed(color=0xf9f9f9)
        response.set_author(name=f'{starter} married to...',
                            icon_url=user_avatar(target))
        response.add_field(name='Stats', value=stats, inline=False)
        response.add_field(name='Spouse List', value=f'```hs\n{spbody}\n```')
    else:
        if page == 1:
            response = discord.Embed(
                color=0xe75a70,
                title=
                f'💔 {starter} not married, nor {mid} proposed, to anyone.')
        else:
            response = discord.Embed(
                color=0xe75a70,
                title=f'💔 {starter.split()[0]} {mid} nobody on page {page}.'
            )
    await message.channel.send(embed=response)
Пример #16
0
async def blockedextensions(cmd: SigmaCommand, message: discord.Message, args: list):
    blocked_words = await cmd.db.get_guild_settings(message.guild.id, 'blocked_extensions')
    if not blocked_words:
        response = discord.Embed(color=0x3B88C3, title='ℹ There are no blocked extensions.')
    else:
        total_count = len(blocked_words)
        blocked_words, page = paginate(blocked_words, args[0] if args else 1, 20)
        blocked_words = [f'.{bw}' for bw in blocked_words]
        showing_count = len(blocked_words)
        title = f'ℹ Extensions blocked on {message.guild.name}'
        response = discord.Embed(color=0x3B88C3, title=title)
        response.description = ' '.join(blocked_words)
        response.set_footer(text=f'[Page {page}] Total: {total_count} | Showing: {showing_count}')
    await message.channel.send(embed=response)
Пример #17
0
async def wfsales(cmd: SigmaCommand, message: discord.Message, args: list):
    sales_api = 'https://deathsnacks.com/wf/data/flashsales_raw.txt'
    async with aiohttp.ClientSession() as session:
        async with session.get(sales_api) as data:
            sales_text = await data.text()
    discount_only = True
    title = 'List of Warframe Items on Sale'
    if args:
        if args[-1].lower() == 'all':
            discount_only = False
            title = 'List of Promoted Warframe Items'
    sales_data_all = parse_sales_data(sales_text, discount_only)
    total_item = len(sales_data_all)
    page = args[0] if args else 1
    sales_data, page = paginate(sales_data_all, page)
    start_range, end_range = (page - 1) * 10, page * 10
    no_discounts = True
    for item in sales_data:
        if item.get('discount') != 0:
            no_discounts = False
            break
    if no_discounts:
        headers = ['Name', 'Platinum']
    else:
        headers = ['Name', 'Platinum', 'Discount']
    if sales_data:
        total_plat = sum([x.get('platinum') for x in sales_data_all])
        sales_data = sorted(sales_data, key=lambda x: x.get('name'))
        stat_block = f'Showing items {start_range}-{end_range}.'
        stat_block += f'\nThere are {total_item} items valued at {total_plat} platinum.'
        item_list = []
        for sale_item in sales_data:
            if no_discounts:
                item_list.append([sale_item.get('name'), sale_item.get('platinum')])
            else:
                item_list.append([sale_item.get('name'), sale_item.get('platinum'), f"-{sale_item.get('discount')}%"])
        item_table = boop(item_list, headers)
        response = discord.Embed(color=0x336699)
        response.set_author(name='Warframe Promotions', icon_url=wf_logo)
        response.description = stat_block
        response.add_field(name=title, value=f'```hs\n{item_table}\n```')
    else:
        response = discord.Embed(color=0x336699, title=f'No items found, try adding the "all" argument.')
    await message.channel.send(embed=response)
Пример #18
0
async def ingame(cmd: SigmaCommand, message: discord.Message, args: list):
    games = {}
    online_count = 0
    playing_count = 0
    total_count = 0
    for member in message.guild.members:
        total_count += 1
        status = str(member.status)
        if status != 'offline':
            online_count += 1
        if not member.bot:
            if member.activity:
                game_name = member.activity.name
                repl_name = game_name.replace(' ', '')
                if repl_name != '':
                    playing_count += 1
                    if game_name not in games:
                        games.update({game_name: 1})
                    else:
                        curr_count = games[game_name]
                        new_count = curr_count + 1
                        games.update({game_name: new_count})
    response = discord.Embed(color=0x1ABC9C)
    sorted_games = sorted(games.items(), key=operator.itemgetter(1), reverse=True)
    page = args[0] if args else 1
    game_list, page = paginate(sorted_games, page)
    start_range, end_range = (page - 1) * 10, page * 10
    out_table_list = []
    game_count = len(sorted_games)
    n = 0
    for key, value in game_list:
        n += 1
        index = n + start_range
        if len(key) > 32:
            key = key[:32] + '...'
        out_table_list.append(
            [str(index), key.title(), value, str(((value / playing_count) * 10000) // 100).split('.')[0] + '%'])
    out = boop(out_table_list)
    general_stats_list = [['Online', online_count], ['In-Game', playing_count], ['Unique Games', game_count]]
    out_block = f'```hs\n{boop(general_stats_list)}\n```'
    response.add_field(name='👾 Current Gaming Statistics on ' + message.guild.name, value=out_block, inline=False)
    response.add_field(name=f'🎮 By Game on Page {page}', value='```haskell\n' + out + '\n```', inline=False)
    await message.channel.send(embed=response)
Пример #19
0
async def inrole(cmd: SigmaCommand, message: discord.Message, args: list):
    if args:
        lookup = args[0].lower()
        role_search = discord.utils.find(lambda x: x.name.lower() == lookup,
                                         message.guild.roles)
        if role_search:
            state = None
            members = []
            if len(args) > 1:
                if args[1].startswith('--'):
                    state_name = args[1][2:].lower()
                    if state_name in accepted_states:
                        state = state_name
            for member in message.guild.members:
                if role_search in member.roles:
                    if state:
                        if member.status.name == state:
                            members.append([member.name, member.top_role.name])
                    else:
                        members.append([member.name, member.top_role.name])
            if members:
                page = args[-1] if len(args) > 1 and args[-1].isdigit() else 1
                members, page = paginate(sorted(members), page)
                response = discord.Embed(color=role_search.color)
                total_members = message.guild.member_count
                value = f'```py\n{len(members)} of {total_members} have the {role_search.name} role. Page {page}\n```'
                headers = ['Name', 'Top Role']
                members_table = boop(members, headers)
                response.add_field(name='📄 Details', value=value, inline=False)
                response.add_field(name='👥 Members',
                                   value=f'```hs\n{members_table}\n```',
                                   inline=False)
            else:
                response = discord.Embed(
                    color=0x696969,
                    title=f'🔍 No users have the {role_search.name} role.')
        else:
            response = discord.Embed(color=0x696969,
                                     title=f'🔍 {lookup} not found.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
Пример #20
0
async def whoplays(cmd: SigmaCommand, message: discord.Message, args: list):
    if args:
        if args[0].isdigit():
            game_title = ' '.join(args[1:])
            page = True
        else:
            game_title = ' '.join(args)
            page = False
        game_name = None
        gamer_list = []
        x, y = 0, 0
        for member in message.guild.members:
            if member.activity:
                x += 1
                if member.activity.name.lower() == game_title.lower():
                    if not game_name:
                        game_name = member.activity.name
                    gamer_list.append(member.name)
                    y += 1
        title = f'{y}/{x} people are playing {game_name}'
        if gamer_list:
            total_gamers = len(gamer_list)
            page = args[0] if page else 1
            gamer_list, page = paginate(sorted(gamer_list), page, 20)
            gamers = '\n- ' + '\n- '.join(gamer_list)
            response = discord.Embed(color=0x1ABC9C)
            response.add_field(name=title, value=gamers)
            response.set_footer(
                text=
                f'[Page {page}] Showing {len(gamer_list)} user out of {total_gamers}.'
            )
        else:
            response = discord.Embed(
                color=0x696969,
                title=f'🔍 No users are currently playing {game_title}.')
    else:
        response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
async def customcommands(cmd: SigmaCommand, message: discord.Message,
                         args: list):
    custom_commands = await cmd.db.get_guild_settings(message.guild.id,
                                                      'custom_commands')
    if custom_commands:
        custom_commands = sorted(list(custom_commands.keys()))
        cmd_count = len(custom_commands)
        page = args[0] if args else 1
        commands, page = paginate(custom_commands, page)
        start_range = (page - 1) * 10
        if commands:
            ender = 's' if cmd_count > 1 else ''
            summary = f'Showing **{len(commands)}** command{ender} from Page **#{page}**.'
            summary += f'\n{message.guild.name} has **{cmd_count}** custom command{ender}.'
            pfx = await cmd.db.get_prefix(message)
            loop_index = start_range
            cmd_list_lines = []
            for key in commands:
                loop_index += 1
                list_line = f'**{loop_index}**: {pfx}{key}'
                cmd_list_lines.append(list_line)
            cmd_list = '\n'.join(cmd_list_lines)
            srv_color = await get_image_colors(message.guild.icon_url)
            response = discord.Embed(color=srv_color)
            response.set_author(name='Custom Commands',
                                icon_url=message.guild.icon_url)
            response.add_field(name='Summary', value=summary, inline=False)
            response.add_field(name='Command List',
                               value=cmd_list,
                               inline=False)
        else:
            response = discord.Embed(color=0xBE1931,
                                     title='❗ This page is empty.')
    else:
        response = discord.Embed(color=0xBE1931,
                                 title='❗ This server has no custom commands.')
    await message.channel.send(embed=response)
Пример #22
0
async def commands(cmd: SigmaCommand, message: discord.Message, args: list):
    if args:
        lookup = args[0].lower()
        command_items = cmd.bot.modules.commands
        command_list = []
        for command in command_items:
            command = command_items[command]
            category = command.category.lower()
            if category == lookup:
                if message.guild:
                    permission = ServerCommandPermissions(command, message)
                    await permission.check_perms()
                else:
                    permission = None
                command_list.append([command, permission])
        if command_list:
            module_list = sorted(command_list, key=lambda x: x[0].name)
            module_count = len(module_list)
            page = args[1] if len(args) > 1 else 1
            module_list, page = paginate(module_list, page, 30)
            output = ''
            for module_item, module_perm in module_list:
                if module_perm:
                    if module_perm.permitted:
                        output += f'\n- {module_item.name}'
                    else:
                        output += f'\n- ⛔ {module_item.name}'
                else:
                    output += f'\n- {module_item.name}'
                if module_item.alts:
                    output += f' [{", ".join(module_item.alts)}]'
            if output:
                title_text = f'```py\nThere are {module_count} commands.\n```'
                response = discord.Embed(color=0x1B6F5F)
                response.add_field(name=f'{lookup.upper()} Commands',
                                   value=title_text,
                                   inline=False)
                response.add_field(name=f'Commands List | Page {page}',
                                   value=f'```yml\n{output}\n```',
                                   inline=False)
            else:
                response = discord.Embed(
                    color=0x696969, title=f'🔍 No commands on page {page}.')
        else:
            response = discord.Embed(color=0x696969,
                                     title='🔍 Module not found.')
    else:
        pfx = await cmd.db.get_prefix(message)
        command_list = cmd.bot.modules.commands
        module_list = []
        for command in command_list:
            command = command_list[command]
            category = command.category.upper()
            if category not in module_list:
                module_list.append(category)
        module_list = sorted(module_list)
        output = ''
        for module_item in module_list:
            output += f'\n- {module_item}'
        module_list_out = f'```py\nThere are {len(module_list)} modules.\n```'
        response = discord.Embed(color=0x1B6F5F)
        response.add_field(name='Modules', value=module_list_out, inline=False)
        response.add_field(name='Module List',
                           value=f'```yml\n{output}\n```',
                           inline=False)
        response.set_footer(
            text=
            f'Type {pfx}{cmd.name} [module] to see commands in that module.')
    await message.channel.send(embed=response)
Пример #23
0
async def wfvoidtrader(cmd: SigmaCommand, message: discord.Message,
                       args: list):
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(
                    'https://deathsnacks.com/wf/data/voidtraders.json'
            ) as data:
                data = await data.read()
                data = json.loads(data)
    except aiohttp.ClientPayloadError:
        data = None
    if data:
        data = data[0]
        all_items = data.get('Manifest') or []
        now_time = arrow.get()
        start_time = arrow.get(data['Activation']['sec'])
        if start_time.timestamp <= now_time.timestamp:
            ending_time = arrow.get(data['Expiry']['sec'])
            headers = ['Item', 'Ducats', 'Credits']
            item_list = []
            total_items = len(all_items)
            total_ducats = 0
            total_credits = 0
            for item in all_items:
                item_name = item.get('ItemType')
                item_ducats = item.get('PrimePrice')
                total_ducats += item_ducats
                item_credits = item.get('RegularPrice')
                total_credits += item_credits
                item_addition = [
                    item_name, str(item_ducats),
                    str(item_credits)
                ]
                item_list.append(item_addition)
            page = args[0] if args else 1
            item_list, page = paginate(item_list, page)
            if item_list:
                out_table = boop(item_list, headers)
                stats_desc = f'Page {page} | Location: {data.get("Node")}'
                stats_desc += f'\nItems: {total_items} | Ducats: {total_ducats} | Credits: {total_credits}'
                end_human = ending_time.humanize()
                leaves = f'Trader leaves {end_human}'
                response = discord.Embed(color=0x006666,
                                         timestamp=ending_time.datetime)
                response.set_author(name='Warframe Void Trader',
                                    icon_url=baro_icon)
                response.add_field(name='Total Statistics',
                                   value=stats_desc,
                                   inline=False)
                response.add_field(name='Items For Sale',
                                   value=f'```bat\n{out_table}\n```',
                                   inline=False)
                response.set_footer(text=leaves)
            else:
                response = discord.Embed(color=0x006666)
                response.set_author(name=f'No items on this page.',
                                    icon_url=baro_icon)
        else:
            diff = start_time.timestamp - now_time.timestamp
            if diff < 86400:
                comes_time = str(datetime.timedelta(seconds=diff))
            else:
                comes_time = start_time.humanize()
            response = discord.Embed(color=0x006666)
            response.set_author(
                name=f'Void Trader arrives {comes_time} on {data.get("Node")}.',
                icon_url=baro_icon)
    else:
        response = discord.Embed(
            color=0xBE1931, title='❗ Could not retrieve Void Trader data.')
    await message.channel.send(embed=response)
Пример #24
0
 def test_page_size(self):
     nums = list(range(1, 16))
     assert paginate(nums, 1) == (nums[0:10], 1)
     assert paginate(nums, 3) == (nums[10:20], 2)
     assert paginate(nums, 3, 5) == (nums[10:15], 3)
     assert paginate(nums, 4, 5) == (nums[10:15], 3)