async def userinformation(cmd, message, args):
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    response = discord.Embed(color=target.color)
    response.set_author(name=f'{target.display_name}\'s Information', icon_url=user_avatar(target))
    creation_time = arrow.get(target.created_at).format('DD. MMMM YYYY')
    user_text = f'Username: **{target.name}**#{target.discriminator}'
    user_text += f'\nID: **{target.id}**'
    user_text += f'\nStatus: **{str(target.status).replace("dnd", "busy").title()}**'
    user_text += f'\nBot User: **{target.bot}**'
    user_text += f'\nCreated: **{creation_time}**'
    response.add_field(name='User Info', value=user_text, inline=True)
    member_join_time = arrow.get(target.joined_at).format('DD. MMMM YYYY')
    is_moderator = target.permissions_in(message.channel).manage_guild
    member_text = f'Name: **{target.display_name}**'
    member_text += f'\nColor: **{str(target.color).upper()}**'
    member_text += f'\nTop Role: **{target.top_role.name}**'
    member_text += f'\nModerator: **{is_moderator}**'
    member_text += f'\nJoined: **{member_join_time}**'
    response.add_field(name='Member Info', value=member_text, inline=True)
    footer = f'To see the user\'s avatar use the {cmd.bot.get_prefix(message)}avatar command.'
    response.set_footer(text=footer)
    await message.channel.send(None, embed=response)
async def disconnect(cmd, message, args):
    if message.author.voice:
        same_bound = True
        if message.guild.voice_client:
            if message.guild.voice_client.channel.id != message.author.voice.channel.id:
                same_bound = False
        if same_bound:
            if message.guild.voice_client:
                await message.guild.voice_client.disconnect()
                if message.guild.id in cmd.bot.music.queues:
                    del cmd.bot.music.queues[message.guild.id]
                response = discord.Embed(color=0x66CC66,
                                         title='✅ Disconnected and purged.')
                requester = f'{message.author.name}#{message.author.discriminator}'
                response.set_author(name=requester,
                                    icon_url=user_avatar(message.author))
            else:
                response = discord.Embed(
                    color=ERROR, title='❗ I am not connected to any channel.')
        else:
            response = discord.Embed(
                color=ERROR, title='❗ You are not in my voice channel.')
    else:
        response = discord.Embed(color=ERROR,
                                 title='❗ You are not in a voice channel.')
    await message.channel.send(embed=response)
Exemple #3
0
async def skip(cmd, message, args):
    if message.author.voice:
        same_bound = True
        if message.guild.voice_client:
            if message.guild.voice_client.channel.id != message.author.voice.channel.id:
                same_bound = False
        if same_bound:
            if message.guild.voice_client:
                queue = cmd.bot.music.get_queue(message.guild.id)
                if queue:
                    curr = cmd.bot.music.currents[message.guild.id]
                    message.guild.voice_client.stop()
                    response = discord.Embed(color=0x66CC66,
                                             title=f'✅ Skipping {curr.title}.')
                    requester = f'{message.author.name}#{message.author.discriminator}'
                    response.set_author(name=requester,
                                        icon_url=user_avatar(message.author))
                else:
                    response = discord.Embed(
                        color=ERROR,
                        title='❗ The queue is empty or this is the last song.')
            else:
                response = discord.Embed(
                    color=ERROR, title='❗ I am not connected to any channel.')
        else:
            response = discord.Embed(
                color=ERROR, title='❗ You are not in my voice channel.')
    else:
        response = discord.Embed(color=ERROR,
                                 title='❗ You are not in a voice channel.')
    await message.channel.send(embed=response)
Exemple #4
0
async def inventorystats(cmd, message, args):
    global item_core
    if not item_core:
        item_core = ItemCore(cmd.resource('data'))
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    inv = cmd.db.get_inventory(target)
    item_o_list = []
    for item in inv:
        item_o = item_core.get_item_by_file_id(item['item_file_id'])
        item_o_list.append(item_o)
    item_o_list = sorted(item_o_list, key=lambda x: x.rarity, reverse=True)
    inv = item_o_list
    if inv:
        total_value = 0
        rarity_dict = {}
        type_dict = {}
        for item_o_item in item_o_list:
            total_value += item_o_item.value
            if item_o_item.type.lower() in type_dict:
                type_count = type_dict[item_o_item.type.lower()]
            else:
                type_count = 0
            type_count += 1
            type_dict.update({item_o_item.type.lower(): type_count})
            if item_o_item.rarity_name in rarity_dict:
                rare_count = rarity_dict[item_o_item.rarity_name]
            else:
                rare_count = 0
            rare_count += 1
            rarity_dict.update({item_o_item.rarity_name: rare_count})
        type_keys = ['fish', 'plant', 'animal']
        type_list = []
        for type_key in type_keys:
            if type_key in type_dict:
                type_num = type_dict[type_key]
            else:
                type_num = 0
            type_list.append([type_key.upper(), type_num])
        type_out = boop(type_list)
        rare_keys = ['common', 'uncommon', 'rare', 'legendary', 'prime',
                     'spectral', 'ethereal', 'antimatter', 'omnipotent']
        rare_list = []
        for rare_key in rare_keys:
            if rare_key in rarity_dict:
                rare_num = rarity_dict[rare_key]
            else:
                rare_num = 0
            rare_list.append([rare_key.upper(), rare_num])
        rare_out = boop(rare_list)
        response = discord.Embed(color=0xc16a4f)
        response.set_author(name=f'{target.name}#{target.discriminator}', icon_url=user_avatar(target))
        response.add_field(name='Items by Type', value=f'```py\n{type_out}\n```', inline=False)
        response.add_field(name='Items by Rarity', value=f'```py\n{rare_out}\n```', inline=False)
    else:
        response = discord.Embed(color=0xc6e4b5, title='💸 Totally empty...')
    await message.channel.send(embed=response)
Exemple #5
0
async def remindme(cmd, message, args):
    if args:
        time_req = args[0]
        try:
            in_seconds = convert_to_seconds(time_req)
            upper_limit = 7776000
            if in_seconds <= upper_limit:
                rem_count = cmd.db[cmd.db.db_cfg.database].Reminders.find({
                    'UserID':
                    message.author.id
                }).count()
                rem_limit = 15
                if rem_count < rem_limit:
                    if len(args) > 1:
                        text_message = ' '.join(args[1:])
                    else:
                        text_message = 'No reminder message set.'
                    execution_stamp = arrow.utcnow().timestamp + in_seconds
                    timestamp = arrow.get(execution_stamp).datetime
                    if in_seconds < 60:
                        time_diff = f'In {in_seconds} seconds'
                    else:
                        time_diff = arrow.get(execution_stamp + 5).humanize(
                            arrow.utcnow())
                    reminder_id = secrets.token_hex(2)
                    reminder_data = {
                        'ReminderID': reminder_id,
                        'UserID': message.author.id,
                        'CreationStamp': arrow.utcnow().timestamp,
                        'ExecutionStamp': execution_stamp,
                        'ChannelID': message.channel.id,
                        'ServerID': message.guild.id,
                        'TextMessage': text_message
                    }
                    cmd.db[cmd.db.db_cfg.database]['Reminders'].insert_one(
                        reminder_data)
                    response = discord.Embed(color=0x66CC66,
                                             timestamp=timestamp)
                    response.description = text_message
                    response.set_author(name=f'Reminder {reminder_id} Created',
                                        icon_url=user_avatar(message.author))
                    response.set_footer(text=f'Executes: {time_diff.title()}')
                else:
                    response = discord.Embed(
                        color=ERROR,
                        title='❗ You already have 15 reminders pending.')
            else:
                response = discord.Embed(
                    color=ERROR, title='❗ Reminders have a limit of 90 days.')
        except LookupError:
            response = discord.Embed(color=ERROR,
                                     title='❗ Please use the format HH:MM:SS.')
        except ValueError:
            response = discord.Embed(color=ERROR,
                                     title='❗ Inputted value is invalid.')
    else:
        response = discord.Embed(color=ERROR, title='❗ No arguments inputted.')
    await message.channel.send(embed=response)
Exemple #6
0
async def unqueue(cmd, message, args):
    if args:
        if message.author.voice:
            same_bound = True
            if message.guild.voice_client:
                if message.guild.voice_client.channel.id != message.author.voice.channel.id:
                    same_bound = False
            if same_bound:
                if message.guild.voice_client:
                    queue = cmd.bot.music.get_queue(message.guild.id)
                    if not queue.empty():
                        try:
                            order_num = int(args[0])
                            if order_num >= 1:
                                order_num -= 1
                            queue_list = await cmd.bot.music.listify_queue(
                                queue)
                            queue_size = len(queue_list)
                            if order_num <= queue_size - 1:
                                item = queue_list[order_num]
                                queue_list.remove(item)
                                new_queue = Queue()
                                for list_item in queue_list:
                                    await new_queue.put(list_item)
                                cmd.bot.music.queues.update(
                                    {message.guild.id: new_queue})
                                response = discord.Embed(
                                    color=0x66CC66,
                                    title=f'✅ Removed {item.title}.')
                                requester = f'{message.author.name}#{message.author.discriminator}'
                                response.set_author(name=requester,
                                                    icon_url=user_avatar(
                                                        message.author))
                            else:
                                response = discord.Embed(
                                    color=ERROR, title='❗ Input out of range.')
                        except ValueError:
                            response = discord.Embed(
                                color=ERROR,
                                title='❗ Invalid input. Numbers only.')
                    else:
                        response = discord.Embed(color=ERROR,
                                                 title='❗ The queue is empty.')
                else:
                    response = discord.Embed(
                        color=ERROR,
                        title='❗ I am not connected to any channel.')
            else:
                response = discord.Embed(
                    color=ERROR, title='❗ You are not in my voice channel.')
        else:
            response = discord.Embed(color=ERROR,
                                     title='❗ You are not in a voice channel.')
    else:
        response = discord.Embed(color=ERROR, title='❗ Nothing inputted.')
    await message.channel.send(embed=response)
Exemple #7
0
async def impersonate(cmd, message, args):
    if not cmd.bot.cool_down.on_cooldown(cmd.name, message.author):
        if args:
            if message.mentions:
                target = message.mentions[0]
            else:
                target = discord.utils.find(
                    lambda x: x.name.lower() == ' '.join(args).lower(),
                    message.guild.members)
        else:
            target = message.author
        if target:
            cmd.bot.cool_down.set_cooldown(cmd.name, message.author, 20)
            init_embed = discord.Embed(color=0xbdddf4,
                                       title='💭 Hmm... Let me think...')
            init_message = await message.channel.send(embed=init_embed)
            chain_data = cmd.db[
                cmd.db.db_cfg.database]['MarkovChains'].find_one(
                    {'UserID': target.id})
            if chain_data:
                total_string = ' '.join(chain_data['Chain'])
                total_string = ftfy.fix_text(total_string)
                chain = await cmd.bot.loop.run_in_executor(
                    threads, functools.partial(markovify.Text, total_string))
                chain_function = functools.partial(chain.make_short_sentence,
                                                   max_chars=150)
                task = cmd.bot.loop.run_in_executor(threads, chain_function)
                sentence = await task
                if not sentence:
                    response = discord.Embed(
                        color=ERROR,
                        title='😖 I could not think of anything...')
                else:
                    sentence = ftfy.fix_text(sentence)
                    response = discord.Embed(color=0xbdddf4)
                    response.set_author(name=target.name,
                                        icon_url=user_avatar(target))
                    response.add_field(name='💭 Hmm... something like...',
                                       value=sentence)
            else:
                response = discord.Embed(color=0x696969)
                prefix = cmd.bot.get_prefix(message)
                title = f'🔍 Chain Data Not Found For {target.name}'
                value = f'You can make one with `{prefix}collectchain @{target.name} #channel`!'
                response.add_field(name=title, value=value)
            await init_message.edit(embed=response)
        else:
            no_target = discord.Embed(color=ERROR, title='❗ No user targeted.')
            await message.channel.send(embed=no_target)
    else:
        timeout = cmd.bot.cool_down.get_cooldown(cmd.name, message.author)
        on_cooldown = discord.Embed(
            color=0xccffff,
            title=f'❄ On cooldown for another {timeout} seconds.')
        await message.channel.send(embed=on_cooldown)
Exemple #8
0
async def leave_move_log(ev, guild):
    if ev.bot.cfg.pref.movelog_channel:
        mlc_id = ev.bot.cfg.pref.movelog_channel
        mlc = discord.utils.find(lambda x: x.id == mlc_id,
                                 ev.bot.get_all_channels())
        if mlc:
            if guild.icon_url:
                icon = guild.icon_url
            else:
                icon = user_avatar(guild.owner)
            log_embed = discord.Embed(color=ERROR)
            log_embed.set_author(name='Left A Guild', icon_url=icon, url=icon)
            make_move_log_embed(log_embed, guild)
            await mlc.send(embed=log_embed)
Exemple #9
0
async def cook(cmd, message, args):
    global item_core
    global recipe_core
    if not item_core:
        item_core = ItemCore(cmd.resource('data'))
    if not recipe_core:
        recipe_core = RecipeCore(cmd.resource('data'))
    if args:
        lookup = ' '.join(args)
        recipe = recipe_core.find_recipe(lookup)
        used_items = []
        if recipe:
            req_satisfied = True
            for ingredient in recipe.ingredients:
                user_inv = cmd.db.get_inventory(message.author)
                in_inventory = False
                for item in user_inv:
                    if item['item_file_id'] == ingredient.file_id:
                        used_items.append(item)
                        in_inventory = True
                        break
                if not in_inventory:
                    req_satisfied = False
            if req_satisfied:
                cooked_item_data = item_core.get_item_by_name(
                    recipe.name).generate_inventory_item()
                cmd.db.add_to_inventory(message.author, cooked_item_data)
                for req_item in used_items:
                    cmd.db.del_from_inventory(message.author,
                                              req_item['item_id'])
                quality = cook_quality[cooked_item_data['quality']]
                connector = 'a'
                if quality[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                    connector = 'an'
                head_title = f'{recipe.icon} You made {connector} {quality.lower()} {recipe.name}'
                response = discord.Embed(color=recipe.color, title=head_title)
                response.set_author(name=message.author.display_name,
                                    icon_url=user_avatar(message.author))
            else:
                response = discord.Embed(
                    color=0xBE1931, title=f'❗ You\'re missing ingredients.')
        else:
            response = discord.Embed(color=0x696969,
                                     title=f'🔍 I couldn\'t find that.')
    else:
        response = discord.Embed(color=0xBE1931, title=f'❗ Nothing inputted.')
    await message.channel.send(embed=response)
Exemple #10
0
 async def notify_channel_of_special(message, all_channels, channel_id,
                                     item):
     if channel_id:
         target = discord.utils.find(lambda x: x.id == channel_id,
                                     all_channels)
         if target:
             connector = 'a'
             if item.rarity_name[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                 connector = 'an'
             response_title = f'{item.icon} {connector.title()} {item.rarity_name} {item.name} has been found!'
             response = discord.Embed(color=item.color,
                                      title=response_title)
             response.set_author(name=f'{message.author.display_name}',
                                 icon_url=user_avatar(message.author))
             response.set_footer(text=f'From {message.guild.name}.',
                                 icon_url=message.guild.icon_url)
             await target.send(embed=response)
Exemple #11
0
async def nowplaying(cmd, message, args):
    if message.guild.id in cmd.bot.music.currents:
        item = cmd.bot.music.currents[message.guild.id]
        duration = str(datetime.timedelta(seconds=item.duration))
        author = f'{item.requester.name}#{item.requester.discriminator}'
        response = discord.Embed(color=0x3B88C3)
        response.add_field(name='🎵 Now Playing', value=item.title)
        response.set_thumbnail(url=item.thumbnail)
        response.set_author(name=author,
                            icon_url=user_avatar(item.requester),
                            url=item.url)
        response.set_footer(
            text=f'Duration: {duration} | Tip: The author\'s name is a link.')
    else:
        response = discord.Embed(color=ERROR,
                                 title='❗ No currently playing song data.')
    await message.channel.send(embed=response)
Exemple #12
0
async def myreminders(cmd, message, args):
    here = False
    if args:
        if args[-1].lower() == 'here':
            here = True
    if here:
        lookup_data = {'UserID': message.author.id, 'ChannelID': message.channel.id}
    else:
        lookup_data = {'UserID': message.author.id}
    all_reminders = cmd.db[cmd.db.db_cfg.database].Reminders.find(lookup_data)
    reminder_count = all_reminders.count()
    if reminder_count:
        if reminder_count == 1:
            ender = 'reminder'
        else:
            ender = 'reminders'
        if here:
            reminder_list_title = f'You have {reminder_count} pending {ender} in #{message.channel.name}.'
        else:
            reminder_list_title = f'You have {reminder_count} pending {ender}.'
        reminder_list = ''
        for reminder in all_reminders:
            human_time = arrow.get(reminder['ExecutionStamp']).humanize(arrow.utcnow())
            channel = discord.utils.find(lambda x: x.id == reminder['ChannelID'], cmd.bot.get_all_channels())
            if channel:
                chan_name = f'**#{channel.name}**'
                srv_name = f'**{channel.guild.name}**'
            else:
                chan_name = '*{No Channel}*'
                srv_name = '*{No Server}*'
            rem_id = reminder['ReminderID']
            reminder_list += f'\n`{rem_id}` in {chan_name} on {srv_name} {human_time}'
        strip_clr = await get_image_colors(user_avatar(message.author))
        response = discord.Embed(color=strip_clr)
        response.set_author(name=f'{message.author.display_name}\'s Reminders', icon_url=user_avatar(message.author))
        response.add_field(name='Reminder Count', value=reminder_list_title, inline=False)
        response.add_field(name='Reminder List', value=reminder_list, inline=False)
    else:
        response = discord.Embed(color=0x696969, title='🔍 You have no pending reminders.')
    await message.channel.send(embed=response)
async def clockwork_function_reminder_clockwork(ev):
    while True:
        reminders = ev.db[ev.db.db_cfg.database]['Reminders'].find({})
        for reminder in reminders:
            current_stamp = arrow.utcnow().timestamp
            execution_stamp = reminder['ExecutionStamp']
            if current_stamp > execution_stamp:
                ev.db[ev.db.db_cfg.database]['Reminders'].delete_one(
                    {'ReminderID': reminder['ReminderID']})
                channel = discord.utils.find(
                    lambda x: x.id == reminder['ChannelID'],
                    ev.bot.get_all_channels())
                author = discord.utils.find(
                    lambda x: x.id == reminder['UserID'],
                    ev.bot.get_all_members())
                if channel:
                    target = channel
                elif author:
                    target = author
                else:
                    target = None
                if target:
                    response = discord.Embed(
                        color=0x1ABC9C,
                        timestamp=arrow.get(
                            reminder['CreationStamp']).datetime)
                    if author:
                        response.set_author(name=author.name,
                                            icon_url=user_avatar(author))
                    response.add_field(
                        name='⏰ Reminder Message',
                        value=f"```\n{reminder['TextMessage']}\n```")
                    try:
                        if author:
                            await target.send(author.mention, embed=response)
                        else:
                            await target.send(embed=response)
                    except discord.ClientException:
                        pass
        await asyncio.sleep(1)
Exemple #14
0
async def avatar(cmd, message, args):
    gif = False
    auto_color = False
    if args:
        if args[-1].lower() == 'gif':
            gif = True
        elif args[-1].lower() == 'auto':
            auto_color = True
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    ava_url = user_avatar(target, gif)
    if auto_color:
        color = await get_image_colors(ava_url)
    else:
        color = target.color
    embed = discord.Embed(color=color)
    if auto_color:
        embed.description = f'Dominant Color: #{str(hex(color)).split("x")[1].upper()}'
    embed.set_image(url=ava_url)
    await message.channel.send(None, embed=embed)
async def reminderinfo(cmd, message, args):
    if args:
        rem_id = args[0].lower()
        lookup_data = {'UserID': message.author.id, 'ReminderID': rem_id}
        reminder = cmd.db[cmd.db.db_cfg.database].Reminders.find_one(
            lookup_data)
        if reminder:
            execution_stamp = reminder['ExecutionStamp']
            text_message = reminder['TextMessage']
            timestamp = arrow.get(execution_stamp).datetime
            human_time = arrow.get(execution_stamp).humanize(arrow.utcnow())
            auth_title = f'{message.author.display_name}\'s Reminder: {rem_id}'
            channel = discord.utils.find(
                lambda x: x.id == reminder['ChannelID'],
                cmd.bot.get_all_channels())
            if channel:
                chan_name = f'**#{channel.name}**'
                srv_name = f'**{channel.guild.name}**'
            else:
                chan_name = '*{No Channel}*'
                srv_name = '*{No Server}*'
            location_text = f'Executes in {chan_name} on {srv_name} {human_time}.'
            response = discord.Embed(color=0x66CC66, timestamp=timestamp)
            response.add_field(name='🏛 Location',
                               value=location_text,
                               inline=False)
            response.add_field(name='🗒 Reminder Text',
                               value=text_message,
                               inline=False)
            response.set_author(name=auth_title,
                                icon_url=user_avatar(message.author))
        else:
            response = discord.Embed(color=0x696969,
                                     title=f'🔍 Reminder `{rem_id}` not found.')
    else:
        response = discord.Embed(color=ERROR,
                                 title='❗ No reminder ID inputted.')
    await message.channel.send(embed=response)
Exemple #16
0
async def shuffle(cmd, message, args):
    if message.author.voice:
        same_bound = True
        if message.guild.voice_client:
            if message.guild.voice_client.channel.id != message.author.voice.channel.id:
                same_bound = False
        if same_bound:
            if message.guild.voice_client:
                queue = cmd.bot.music.get_queue(message.guild.id)
                if queue:
                    queue_list = await cmd.bot.music.listify_queue(queue)
                    queue_count = len(queue_list)
                    new_queue = Queue()
                    while queue_list:
                        await new_queue.put(
                            queue_list.pop(secrets.randbelow(len(queue_list))))
                    cmd.bot.music.queues.update({message.guild.id: new_queue})
                    response = discord.Embed(
                        color=0x3B88C3,
                        title=f'🔀 Shuffled {queue_count} songs.')
                    requester = f'{message.author.name}#{message.author.discriminator}'
                    response.set_author(name=requester,
                                        icon_url=user_avatar(message.author))
                else:
                    response = discord.Embed(color=ERROR,
                                             title='❗ The queue is empty.')
            else:
                response = discord.Embed(
                    color=ERROR, title='❗ I am not connected to any channel.')
        else:
            response = discord.Embed(
                color=ERROR, title='❗ You are not in my voice channel.')
    else:
        response = discord.Embed(color=ERROR,
                                 title='❗ You are not in a voice channel.')
    await message.channel.send(embed=response)
Exemple #17
0
async def inventory(cmd, message, args):
    global item_core
    if not item_core:
        item_core = ItemCore(cmd.resource('data'))
    if message.mentions:
        target = message.mentions[0]
    else:
        target = message.author
    upgrade_file = cmd.db[cmd.db.db_cfg.database].Upgrades.find_one(
        {'UserID': target.id})
    if upgrade_file is None:
        cmd.db[cmd.db.db_cfg.database].Upgrades.insert_one(
            {'UserID': target.id})
        upgrade_file = {}
    if 'storage' in upgrade_file:
        storage = upgrade_file['storage']
    else:
        storage = 0
    inv_limit = 64 + (8 * storage)
    page_number = 1
    if args:
        try:
            page_number = abs(int(args[0]))
            if page_number == 0:
                page_number = 1
        except TypeError:
            page_number = 1
        except ValueError:
            page_number = 1
    start_range = (page_number - 1) * 10
    end_range = page_number * 10
    inv = cmd.db.get_inventory(target)
    total_inv = len(inv)
    item_o_list = []
    for item in inv:
        item_o = item_core.get_item_by_file_id(item['item_file_id'])
        item_o_list.append(item_o)
    item_o_list = sorted(item_o_list, key=lambda x: x.rarity, reverse=True)
    inv = item_o_list[start_range:end_range]
    if inv:
        headers = ['Type', 'Item', 'Value', 'Rarity']
        to_format = []
        total_value = 0
        for item_o_item in inv:
            to_format.append([
                item_o_item.type, item_o_item.name, 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'{target.name}#{target.discriminator}',
                            icon_url=user_avatar(target))
        inv_text = f'Showing items {start_range}-{end_range}.'
        inv_text += f'\nYou have {total_inv}/{inv_limit} items in your inventory.'
        inv_text += f'\nTotal value of your 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_number}',
                           value=f'```hs\n{output}\n```',
                           inline=False)
    else:
        response = discord.Embed(color=0xc6e4b5, title='💸 Totally empty...')
    await message.channel.send(embed=response)
Exemple #18
0
async def play(cmd, message, args):
    if message.channel.name == 'music':
        if message.author.voice:
            same_bound = True
            if message.guild.voice_client:
                if message.guild.voice_client.channel.id != message.author.voice.channel.id:
                    same_bound = False
            if same_bound:
                if not message.guild.voice_client:
                    await cmd.bot.modules.commands['summon'].execute(
                        message, args)
                if args:
                    await cmd.bot.modules.commands['queue'].execute(
                        message, args)
                queue = cmd.bot.music.get_queue(message.guild.id)
                if not queue.empty():
                    while not queue.empty():
                        if not message.guild.voice_client:
                            return
                        if message.guild.voice_client.is_playing():
                            return
                        item = await queue.get()
                        if message.guild.id in cmd.bot.music.repeaters:
                            await queue.put(item)
                        init_song_embed = discord.Embed(
                            color=0x3B88C3,
                            title=f'🔽 Downloading {item.title}...')
                        init_song_msg = await message.channel.send(
                            embed=init_song_embed)
                        await item.create_player(message.guild.voice_client)
                        await add_special_stats(cmd.db, 'songs_played')
                        cmd.bot.music.currents.update({message.guild.id: item})
                        duration = str(
                            datetime.timedelta(seconds=item.duration))
                        author = f'{item.requester.name}#{item.requester.discriminator}'
                        song_embed = discord.Embed(color=0x3B88C3)
                        song_embed.add_field(name='🎵 Now Playing',
                                             value=item.title)
                        song_embed.set_thumbnail(url=item.thumbnail)
                        song_embed.set_author(name=author,
                                              icon_url=user_avatar(
                                                  item.requester),
                                              url=item.url)
                        song_embed.set_footer(text=f'Duration: {duration}')
                        await init_song_msg.edit(embed=song_embed)
                        while player_active(message.guild.voice_client):
                            await asyncio.sleep(2)
                    response = discord.Embed(color=0x3B88C3,
                                             title='🎵 Queue complete.')
                    if message.guild.voice_client:
                        await message.guild.voice_client.disconnect()
                        if message.guild.id in cmd.bot.music.queues:
                            del cmd.bot.music.queues[message.guild.id]
                else:
                    response = discord.Embed(color=ERROR,
                                             title='❗ The queue is empty.')
            else:
                response = discord.Embed(
                    color=ERROR,
                    title='❗ Channel miss-match prevented me from playing.')
        else:
            response = discord.Embed(color=ERROR,
                                     title='❗ You are not in a voice channel.')
    else:
        response = discord.Embed(
            color=ERROR,
            title='❗ This Command is only usable in a Music Channel.')
    await message.channel.send(embed=response)
Exemple #19
0
async def slots(cmd, message, args):
    currency_icon = cmd.bot.cfg.pref.currency_icon
    currency = cmd.bot.cfg.pref.currency
    current_kud = cmd.db.get_currency(message.author, message.guild)['current']
    if args:
        try:
            bet = abs(int(args[0]))
        except ValueError:
            bet = 10
    else:
        bet = 10
    if current_kud >= bet:
        if not cmd.bot.cool_down.on_cooldown(cmd.name, message.author):
            upgrade_file = cmd.db[cmd.db.db_cfg.database].Upgrades.find_one(
                {'UserID': message.author.id})
            if upgrade_file is None:
                cmd.db[cmd.db.db_cfg.database].Upgrades.insert_one(
                    {'UserID': message.author.id})
                upgrade_file = {}
            base_cooldown = 20
            if 'stamina' in upgrade_file:
                stamina = upgrade_file['stamina']
            else:
                stamina = 0
            cooldown = int(base_cooldown - ((base_cooldown / 100) *
                                            (stamina * 0.5)))
            cmd.bot.cool_down.set_cooldown(cmd.name, message.author, cooldown)
            cmd.db.rmv_currency(message.author, bet)
            out_list = []
            for x in range(0, 3):
                temp_list = []
                init_symb = []
                for y in range(0, 3):
                    if not init_symb:
                        symbol_choice = secrets.choice(symbols)
                        init_symb.append(symbol_choice)
                    else:
                        roll = secrets.randbelow(bet + 40)
                        if roll == 0:
                            symbol_choice = secrets.choice(init_symb)
                        else:
                            temp_symb = []
                            for symbol_item in symbols:
                                temp_symb.append(symbol_item)
                            for init_symb_item in init_symb:
                                temp_symb.remove(init_symb_item)
                            symbol_choice = secrets.choice(temp_symb)
                            init_symb.append(symbol_choice)
                    temp_list.append(symbol_choice)
                out_list.append(temp_list)
            slot_lines = f'⏸{"".join(out_list[0])}⏸'
            slot_lines += f'\n▶{"".join(out_list[1])}◀'
            slot_lines += f'\n⏸{"".join(out_list[2])}⏸'
            combination = out_list[1]
            three_comb = bool(
                combination[0] == combination[1] == combination[2])
            two_comb_one = bool(combination[0] == combination[1])
            two_comb_two = bool(combination[0] == combination[2])
            two_comb_three = bool(combination[1] == combination[2])
            if three_comb:
                win = True
                announce = True
                winnings = int(bet * (rarity_rewards[combination[0]] *
                                      (bet // 2)))
            elif two_comb_one or two_comb_two or two_comb_three:
                if combination[0] == combination[1]:
                    win_comb = combination[0]
                elif combination[0] == combination[2]:
                    win_comb = combination[0]
                elif combination[1] == combination[2]:
                    win_comb = combination[1]
                else:
                    win_comb = None
                win = True
                announce = False
                winnings = int(bet * (rarity_rewards[win_comb] * (bet // 5)))
            else:
                win = False
                announce = False
                winnings = 0
            if win:
                color = 0x5dadec
                title = '💎 Congrats, you won!'
                footer = f'{currency_icon} {winnings} {currency} has been awarded.'
                cmd.db.add_currency(message.author,
                                    message.guild,
                                    winnings,
                                    additive=False)
            else:
                color = 0x232323
                title = '💣 Oh my, you lost...'
                footer = f'{currency_icon} {bet} {currency} has been deducted.'
            if announce:
                if 'win_channel' in cmd.cfg:
                    target_channel = discord.utils.find(
                        lambda c: c.id == cmd.cfg['win_channel'],
                        cmd.bot.get_all_channels())
                    announce_embed = discord.Embed(
                        color=0xf9f9f9,
                        title=f'🎰 A user just got 3 {combination[0]}.')
                    announce_embed.set_author(name=message.author.display_name,
                                              icon_url=user_avatar(
                                                  message.author))
                    announce_embed.set_footer(
                        text=f'On: {message.guild.name}.',
                        icon_url=message.guild.icon_url)
                    await target_channel.send(embed=announce_embed)
            response = discord.Embed(color=color)
            response.add_field(name=title, value=slot_lines)
            response.set_footer(text=footer)
        else:
            timeout = cmd.bot.cool_down.get_cooldown(cmd.name, message.author)
            response = discord.Embed(
                color=0x696969,
                title=f'🕙 You can spin again in {timeout} seconds.')
    else:
        response = discord.Embed(color=0xa7d28b,
                                 title=f'💸 You don\'t have enough {currency}.')
    await message.channel.send(embed=response)
Exemple #20
0
async def fish(cmd, message, args):
    global item_core
    if not item_core:
        item_core = ItemCore(cmd.resource('data'))
    if not cmd.bot.cool_down.on_cooldown(cmd.name, message.author):
        upgrade_file = cmd.db[cmd.db.db_cfg.database].Upgrades.find_one(
            {'UserID': message.author.id})
        if upgrade_file is None:
            cmd.db[cmd.db.db_cfg.database].Upgrades.insert_one(
                {'UserID': message.author.id})
            upgrade_file = {}
        inv = cmd.db.get_inventory(message.author)
        if 'storage' in upgrade_file:
            storage = upgrade_file['storage']
        else:
            storage = 0
        inv_limit = 64 + (8 * storage)
        if len(inv) < inv_limit:
            base_cooldown = 60
            if 'stamina' in upgrade_file:
                stamina = upgrade_file['stamina']
            else:
                stamina = 0
            cooldown = int(base_cooldown - ((base_cooldown / 100) *
                                            (stamina * 0.5)))
            cmd.bot.cool_down.set_cooldown(cmd.name, message.author, cooldown)
            rarity = item_core.roll_rarity(cmd.db, message.author.id)
            if args:
                if message.author.id in cmd.bot.cfg.dsc.owners:
                    try:
                        rarity = int(args[0])
                    except TypeError:
                        pass
            item = item_core.pick_item_in_rarity('fish', rarity)
            connector = 'a'
            if item.rarity_name[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                connector = 'an'
            if rarity == 0:
                if item.name[0].lower() in ['a', 'e', 'i', 'o', 'u']:
                    connector = 'an'
                response_title = f'{item.icon} You caught {connector} {item.name} and threw it away!'
            else:
                response_title = f'{item.icon} You caught {connector} {item.rarity_name} {item.name}!'
                data_for_inv = item.generate_inventory_item()
                cmd.db.add_to_inventory(message.author, data_for_inv)
            response = discord.Embed(color=item.color, title=response_title)
            response.set_author(name=message.author.display_name,
                                icon_url=user_avatar(message.author))
            if item.rarity >= 5:
                if 'item_channel' in cmd.cfg:
                    await item_core.notify_channel_of_special(
                        message, cmd.bot.get_all_channels(),
                        cmd.cfg['item_channel'], item)
        else:
            response = discord.Embed(color=0xBE1931,
                                     title=f'❗ Your inventory is full.')
    else:
        timeout = cmd.bot.cool_down.get_cooldown(cmd.name, message.author)
        response = discord.Embed(
            color=0x696969,
            title=f'🕙 Your new bait will be ready in {timeout} seconds.')
    await message.channel.send(embed=response)
Exemple #21
0
async def trivia(cmd, message, args):
    global trivia_cache
    if not cmd.bot.cool_down.on_cooldown(cmd.name, message.author):
        if message.author.id not in ongoing_list:
            ongoing_list.append(message.author.id)
            allotted_time = 20
            if not trivia_cache:
                trivia_api_url = 'https://opentdb.com/api.php?amount=50'
                async with aiohttp.ClientSession() as session:
                    async with session.get(trivia_api_url) as number_get:
                        number_response = await number_get.read()
                        data = json.loads(number_response)
                        trivia_cache += data['results']
            data = trivia_cache.pop(secrets.randbelow(len(trivia_cache)))
            cmd.bot.cool_down.set_cooldown(cmd.name, message.author, 30)
            question = data['question']
            question = ftfy.fix_text(question)
            category = data['category']
            correct_answer = data['correct_answer']
            correct_answer = ftfy.fix_text(correct_answer)
            incorrect_answers = data['incorrect_answers']
            difficulty = data['difficulty']
            kud_reward = awards.get(difficulty) or '10'
            choice_list = [correct_answer] + incorrect_answers
            choice_list = shuffle_questions(choice_list)
            choice_number = 0
            choice_lines = []
            for choice in choice_list:
                choice_number += 1
                choice_line = f'[{choice_number}] {choice}'
                choice_lines.append(choice_line)
            choice_text = '\n'.join(choice_lines)
            choice_text = ftfy.fix_text(choice_text)
            if difficulty == 'easy':
                starter = 'An'
            else:
                starter = 'A'
            question_embed = discord.Embed(color=0xF9F9F9,
                                           title='❔ Here\'s a question!')
            question_embed.description = f'{starter} {difficulty} one from the {category} category.'
            question_embed.add_field(name='Question',
                                     value=question,
                                     inline=False)
            question_embed.add_field(name='Choices',
                                     value=f'```py\n{choice_text}\n```',
                                     inline=False)
            question_embed.set_footer(
                text='Input the number of your chosen answer.')
            question_embed.set_author(name=message.author.display_name,
                                      icon_url=user_avatar(message.author))
            await message.channel.send(embed=question_embed)

            def check_answer(msg):
                if message.channel.id == msg.channel.id:
                    if message.author.id == msg.author.id:
                        try:
                            int(msg.content)
                            number = True
                        except ValueError:
                            number = False
                        if number or (msg.content.title() in choice_list):
                            correct = True
                        else:
                            correct = False
                    else:
                        correct = False
                else:
                    correct = False
                return correct

            try:
                answer_message = await cmd.bot.wait_for('message',
                                                        check=check_answer,
                                                        timeout=allotted_time)
                try:
                    answer_index = int(answer_message.content) - 1
                except ValueError:
                    answer_index = None
                correct_index = get_correct_index(choice_list, correct_answer)
                if answer_index == correct_index or answer_message.content.lower(
                ) == correct_answer.lower():
                    cmd.db.add_currency(answer_message.author, message.guild,
                                        kud_reward)
                    author = answer_message.author.display_name
                    currency = cmd.bot.cfg.pref.currency
                    win_title = f'🎉 Correct, {author}, it was {correct_answer}. You won {kud_reward} {currency}!'
                    final_embed = discord.Embed(color=0x77B255,
                                                title=win_title)
                else:
                    lose_title = f'💣 Ooh, sorry, it was {correct_answer}...'
                    final_embed = discord.Embed(color=0x262626,
                                                title=lose_title)
                await message.channel.send(embed=final_embed)
            except asyncio.TimeoutError:
                timeout_title = f'🕙 Time\'s up! It was {correct_answer}...'
                timeout_embed = discord.Embed(color=0x696969,
                                              title=timeout_title)
                await message.channel.send(embed=timeout_embed)
            if message.author.id in ongoing_list:
                ongoing_list.remove(message.author.id)
        else:
            ongoing_error = discord.Embed(
                color=ERROR, title='❗ There is one already ongoing.')
            await message.channel.send(embed=ongoing_error)
    else:
        timeout = cmd.bot.cool_down.get_cooldown(cmd.name, message.author)
        on_cooldown = discord.Embed(
            color=0xccffff,
            title=f'❄ On cooldown for another {timeout} seconds.')
        await message.channel.send(embed=on_cooldown)
Exemple #22
0
async def collectchain(cmd, message, args):
    global in_use
    global in_use_by
    if in_use:
        response = discord.Embed(color=0x696969,
                                 title='🛠 Currently in use. Try Again Later.')
        response.set_author(name=f'{in_use_by.name}',
                            icon_url=user_avatar(in_use_by))
        await message.channel.send(None, embed=response)
    else:
        if message.mentions:
            target = message.mentions[0]
        else:
            if args:
                target = discord.utils.find(
                    lambda x: x.name.lower() == ' '.join(args).lower(),
                    message.guild.members)
            else:
                target = message.author
        if target:
            if not target.bot:
                start_time = arrow.utcnow().timestamp
                if message.channel_mentions:
                    target_chn = message.channel_mentions[0]
                else:
                    target_chn = message.channel
                collected = 0
                collection = cmd.db[
                    cmd.db.db_cfg.database]['MarkovChains'].find_one(
                        {'UserID': target.id})
                if collection:
                    collection = collection['Chain']
                else:
                    collection = []
                in_use = True
                in_use_by = message.author
                ch_response = discord.Embed(
                    color=0x66CC66,
                    title=
                    '📖 Collecting... You will be sent a DM when I\'m done.')
                await message.channel.send(None, embed=ch_response)
                try:
                    async for log in target_chn.history(limit=100000):
                        if log.author.id == target.id:
                            if log.content:
                                if log.content != '':
                                    if len(log.content) > 3:
                                        if not check_for_bot_prefixes(
                                                cmd.bot.get_prefix(message),
                                                log.content):
                                            if 'http' not in log.content and '```' not in log.content:
                                                if '"' not in log.content:
                                                    content = log.content
                                                    if log.mentions:
                                                        for mention in log.mentions:
                                                            content = content.replace(
                                                                mention.
                                                                mention,
                                                                mention.name)
                                                    if log.channel_mentions:
                                                        for mention in log.channel_mentions:
                                                            content = content.replace(
                                                                mention.
                                                                mention,
                                                                mention.name)
                                                    unallowed_chars = [
                                                        '`', '\n', '\\', '\\n'
                                                    ]
                                                    for char in unallowed_chars:
                                                        content = content.replace(
                                                            char, '')
                                                    if len(content) > 12:
                                                        if not content.endswith(
                                                            ('.' or '?'
                                                             or '!')):
                                                            content += '.'
                                                    if content not in collection:
                                                        collection.append(
                                                            content)
                                                        collected += 1
                                                        if collected >= 5000:
                                                            break
                except Exception:
                    pass
                cmd.db[cmd.db.db_cfg.database]['MarkovChains'].delete_one(
                    {'UserID': target.id})
                data = {'UserID': target.id, 'Chain': collection}
                cmd.db[cmd.db.db_cfg.database]['MarkovChains'].insert_one(data)
                in_use = False
                in_use_by = None
                dm_response = discord.Embed(
                    color=0x66CC66, title=f'📖 {target.name}\'s chain is done!')
                dm_response.add_field(name='Amount Collected',
                                      value=f'```\n{collected}\n```')
                dm_response.add_field(name='Total Amount',
                                      value=f'```\n{len(collection)}\n```')
                dm_response.add_field(
                    name='Time Elapsed',
                    value=f'```\n{arrow.utcnow().timestamp - start_time}s\n```'
                )
                try:
                    await message.author.send(None, embed=dm_response)
                except discord.Forbidden:
                    pass
                await message.channel.send(None, embed=dm_response)
                if message.author.id != target.id:
                    tgt_msg = discord.Embed(
                        color=0x66CC66,
                        title=
                        f'📖 {message.author.name} has made a markov chain for you.'
                    )
                    try:
                        await target.send(None, embed=tgt_msg)
                    except discord.Forbidden:
                        pass
            else:
                response = discord.Embed(
                    color=0xBE1931, title='❗ Nope, no bot chains allowed.')
                await message.channel.send(embed=response)