Ejemplo n.º 1
0
    async def album(self, ctx, link: str = None, *, album_name: str = None):
        '''addalbum [album link] [album name] - Adds an album, link, and name.
        ex; .addalbum https://imgur.com/gallery/MnIjj3n a phone
        and 'pickone a phone' would call this album.
        '''
        if not link or not album_name:
            await ctx.send(
                'Please include a link to the album and a name for the album.')
            return

        possible_links = [
            'https://imgur.com/gallery/', 'https://imgur.com/a/'
        ]  #leaving this for additions later
        if not any(x in link for x in possible_links):
            await ctx.send('That doesnt look like a valid link.')

        else:
            album_name = album_name.lower()
            self.bot.serverconfig = pyson.Pyson(
                f'data/servers/{str(ctx.guild.id)}/config.json')
            if album_name not in self.bot.serverconfig.data.get('albums'):
                self.bot.serverconfig.data['albums'][album_name] = link
                self.bot.serverconfig.save()
                await ctx.send(f'"{album_name}" has been added!')
            else:
                await ctx.send(f'"{album_name}" already exists.')
Ejemplo n.º 2
0
 async def on_member_join(self, member):
     self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(member.guild.id)}.json')
     if not member.bot:
         if str(member.id) not in self.bot.server.data.get('users'):
             new_user = {"itemlist": {}, "points": 0}
             self.bot.server.data['users'][str(member.id)] = new_user
             self.bot.server.save()
Ejemplo n.º 3
0
def get_prefix(bot, message):
    bot.serverconfig = pyson.Pyson(
        f'data/servers/{str(message.guild.id)}/config.json')
    prefix = bot.serverconfig.data.get('config').get('prefix')
    if not prefix:
        prefix = '!'
    return commands.when_mentioned_or(*prefix)(bot, message)
Ejemplo n.º 4
0
 async def remove_item(self, player, item, amount, ctx):
     self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.message.guild.id)}.json')
     new_amount = amount - 1
     self.bot.server.data['users'][str(player)]['itemlist'][item] = int(new_amount)
     if new_amount == 0:
         self.bot.server.data['users'][str(player)]['itemlist'].pop(item, None)
     self.bot.server.save()
Ejemplo n.º 5
0
    async def item_timer(self, player, emoji, ctx):
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.message.guild.id)}.json')
        counter = 0
        while True:
            user_list = []
            for user in self.bot.server.data.get('users'):
                user_list.append(user)

            randomperson = random.choice(user_list)
            if randomperson == player:
                while randomperson == player:
                    randomperson = random.choice(user_list)

            events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
            counter = counter + 1
            points = self.bot.server.data.get('users').get(randomperson).get('points')
            value = self.bot.items.data.get('items').get(emoji).get('value')
            new_points = points + value
            if new_points <= 0:
                new_points = 0
            self.bot.server.data['users'][randomperson]['points'] = int(new_points)
            self.bot.server.save()
            player = await self.bot.get_user_info(int(randomperson))
            embed = discord.Embed(colour=discord.Colour(0xc62828),
                                  description=f'<@{player}> '
                                              f'used <{emoji}> on {player.name}, they now have {new_points} points!')
            await events_channel.send(embed=embed)

            if counter == 10:
                break
            else:
                await  asyncio.sleep(180)
Ejemplo n.º 6
0
    async def inventory(self, ctx, message: str = None):
        '''Inventory [user]
        user is optional - shows players or users inventory.
        '''
        events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
        if message is None:
            try:
                get_inventory = self.bot.server.data.get('users').get(str(ctx.message.author.id)).get('itemlist')
                embed = discord.Embed(title="Inventory", description=ctx.message.author.name,
                                      colour=discord.Colour(0xffeb3b))
                descriptions = ''
                items = ''
                for item in get_inventory:
                    name = self.bot.items.data.get('items').get(item).get('name')
                    description = self.bot.items.data.get('items').get(item).get('description')
                    itemamount = self.bot.server.data.get('users').get(str(ctx.message.author.id)).get('itemlist').get(item)
                    descriptions += f'{description}\n'
                    items += f'{name} x({itemamount})\n'

                embed.add_field(name='Item & Amount', value=items)
                embed.add_field(name='Description', value=descriptions)
                await events_channel.send(embed=embed)
                return
            except:
                embed = discord.Embed(title="Inventory", description=ctx.message.author.name,
                                      colour=discord.Colour(0xffeb3b))
                embed.add_field(name='Item & Amount', value="None")
                embed.add_field(name='Description', value='None')
                await events_channel.send(embed=embed)
                return

        if not ctx.message.raw_mentions:
            await ctx.send('no mentions')
            return

        else:
            try:
                user = ctx.channel.guild.get_member(ctx.message.raw_mentions[0])
                get_inventory = self.bot.server.data.get('users').get(str(ctx.message.raw_mentions[0])).get('itemlist')
                embed = discord.Embed(title="Inventory", description=f'{user.name}', colour=discord.Colour(0xffeb3b))
                descriptions = ''
                items = ''
                for item in get_inventory:
                    name = self.bot.items.data.get('items').get(item).get('name')
                    description = self.bot.items.data.get('items').get(item).get('description')
                    itemamount = self.bot.items.data.get('users').get(str(ctx.message.raw_mentions[0])).get('itemlist').get(item)
                    descriptions += f'{description}\n'
                    items += f'{name} x({itemamount})\n'

                embed.add_field(name='Item & Amount', value=items)
                embed.add_field(name='Description', value=descriptions)
                await events_channel.send(embed=embed)
                return

            except:
                embed = discord.Embed(title="Inventory", description=f'{user.name}', colour=discord.Colour(0xffeb3b))
                embed.add_field(name='Item & Amount', value="None")
                embed.add_field(name='Description', value='None')
                await events_channel.send(embed=embed)
Ejemplo n.º 7
0
    async def pos(self, ctx, message: str = None):
        '''pos [user]
        user is optional - shows players or users position.
        '''
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
        users = self.bot.server.data.get('users')
        events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
        if message is None:
            author = ctx.message.author
            leaderboard = sorted(users, key=lambda x: users[x]['points'], reverse=True)
            position = leaderboard.index(str(author.id))
            embed = discord.Embed(colour=discord.Colour(0x8e24aa),
                                  description=f'{ctx.message.author.name} you are in position {position+1}')
            await events_channel.send(embed=embed)
            return

        elif not ctx.message.raw_mentions:
            await ctx.send('no mentions')
            return
        else:
            user = ctx.channel.guild.get_member(ctx.message.raw_mentions[0])
            leaderboard = sorted(users, key=lambda x: users[x]['points'], reverse=True)
            position = leaderboard.index(str(ctx.message.raw_mentions[0]))
            embed = discord.Embed(colour=discord.Colour(0x8e24aa), description=f'{user.name} is in position {position}')
            await events_channel.send(embed=embed)
Ejemplo n.º 8
0
async def on_message(message):
    if any(mention.name == bot.user.name for mention in message.mentions):
        if len(message.mentions) == 1:
            if message.content == f'<@{message.raw_mentions[0]}>':
                bot.serverconfig = pyson.Pyson(
                    f'data/servers/{str(message.guild.id)}/config.json')
                prefix = bot.serverconfig.data.get('config').get('prefix')
                await message.channel.send(f'my prefix is {prefix}')
    await bot.process_commands(message)
Ejemplo n.º 9
0
    async def points(self, ctx, message: str = None):
        '''points shows current points
        '''
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')

        if message is None:
            get_points = self.bot.server.data.get('users').get(str(ctx.author.id)).get('points')
            await ctx.send(f'{ctx.author.name} you have {get_points} points.')
            return
Ejemplo n.º 10
0
    def predicate(ctx):
        if ctx.author.id == ctx.message.guild.owner.id or ctx.author.guild_permissions.manage_guild:
            return True

        if ctx.author.id in pyson.Pyson(
                f'data/servers/{str(ctx.guild.id)}/config.json').data.get(
                    'config').get('admins'):
            return True

        else:
            raise NotAuthorized
Ejemplo n.º 11
0
    async def on_guild_join(self, guild):
        if f'{str(guild.id)}.json' not in os.listdir("./data/jellybot/servers"):
            self.bot.newserver = pyson.Pyson(f'./data/jellybot/servers/{str(guild.id)}.json', {"users": {}})
            self.bot.newserver.save()

            self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(guild.id)}.json')
            for member in guild.members:
                if not member.bot:
                    if str(member.id) not in self.bot.server.data.get('users'):
                        new_user = {"itemlist": {}, "points": 0}
                        self.bot.server.data['users'][str(member.id)] = new_user
            self.bot.server.save()

        if not any(category.name == "jellybot" for category in guild.categories):
            try:
                create_category = await guild.create_category_channel("jellybot")
                contains = ['jelly-events', 'jelly-leaderboard', 'jelly-commands', 'jelly-questions']
                for channel_name in contains:
                    await guild.create_text_channel(channel_name, category=create_category)
                    await asyncio.sleep(1)
            except:
                await guild.owner.send('I am unable to create the channels I need, please create a category with the '
                                       'channels, "jelly-events, jelly-leaderboard, jelly-commands, jelly-questions"')
Ejemplo n.º 12
0
 async def giveaway(self, ctx):
     while True:
         await asyncio.sleep(600)
         self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.message.guild.id)}.json')
         self.users = self.bot.server.data.get('users')
         pickone = random.choice(list(self.users))
         events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
         user_old_points = self.bot.server.data.get('users').get(pickone).get('points')
         new_points = user_old_points + 10
         self.bot.server.data['users'][pickone]['points'] = int(new_points)
         self.bot.server.save()
         player = await self.bot.get_user_info(int(pickone))
         embed = discord.Embed(colour=discord.Colour(0x7cb342),
                               description=f'{player.name} just recieved 10 points from the giveaway and now has '
                                           f'{new_points} points!')
         await events_channel.send(embed=embed)
Ejemplo n.º 13
0
    async def setprefix(self, ctx, prefix: str = None):
        ''': Change the prefix of the bot, up to two chars.'''
        if not prefix:
            self.bot.serverconfig = pyson.Pyson(
                f'data/servers/{str(ctx.guild.id)}/config.json')
            prefix = self.bot.serverconfig.data.get('config').get('prefix')
            await ctx.send(f'current prefix is {prefix}')
            return
        else:
            if len(prefix) >= 3:
                await ctx.send('Prefix length too long.')
                return

            self.bot.serverconfig.data['config']['prefix'] = prefix
            self.bot.serverconfig.save()
            await ctx.send(f'Prefix updated to {prefix}')
Ejemplo n.º 14
0
    async def addpoints(self, ctx,  person: str=None, amount: str=None):
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
        if not person or not ctx.message.raw_mentions:
            await ctx.send('you forgot to include a person')
            return

        if not amount or not amount.isdigit():
            await ctx.send('invalid amount')
            return

        if str(ctx.message.raw_mentions[0]) in self.bot.server.data.get('users'):
            old_points = self.bot.server.data.get('users').get(str(ctx.message.raw_mentions[0])).get('points')
            self.bot.server.data['users'][str(ctx.message.raw_mentions[0])]['points'] = int(old_points) + int(amount)
            self.bot.server.save()
            await ctx.send('updated users points')
        else:
            await ctx.send('couldnt find that user')
Ejemplo n.º 15
0
    async def start_q_channel(self, ctx):
        while self.timer:
            q_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-questions')
            events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events',)
            self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
            question_list = []
            for question in self.bot.qa.data.get('questions'):
                question_list.append(question)
            pick_question = random.choice(question_list)
            question = self.bot.qa.data.get('questions').get(pick_question).get('question')
            answer = self.bot.qa.data.get('questions').get(pick_question).get('answer')
            await q_channel.send(f'Question time! \n```{question}```')
            guess = None
            self.bot.loop.create_task(self.set_timer())

            def q_channel_check(m):
                return m.channel.name == 'jelly-questions'

            while not guess and self.timer:
                guess_msg = await self.bot.wait_for('message', check=q_channel_check, timeout=30)
                if guess_msg:
                    guess = guess_msg.content.lower()
                    if guess == answer:
                        user_points = self.bot.server.data.get('users').get(str(guess_msg.author.id)).get('points')
                        new_points = user_points + 10
                        self.bot.server.data['users'][str(guess_msg.author.id)]['points'] = int(new_points)
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0x06f116),
                                              description=f'{guess_msg.author.mention},'
                                                          f'you have guessed correctly and earned 10 points, for a total of {new_points}!')
                        await q_channel.send(embed=embed)

                        event = discord.Embed(colour=discord.Colour(0x06f116), description=f'{guess_msg.author.mention}'
                                                                                           f' has answered "{question}" '
                                                                                           f'correctly and earned 10 points, they now have {new_points} points!')
                        await events_channel.send(embed=event)
                        await self.purge_channel(ctx)
                    else:
                        guess = None
            if not guess:
                embed = discord.Embed(colour=discord.Colour(0xf20707),
                                      description=f'Nobody got the question correct!')
                await q_channel.send(embed=embed)
                await self.purge_channel(ctx)

            await asyncio.sleep(1500)
Ejemplo n.º 16
0
async def on_guild_join(guild):
    if not os.path.exists(f"./data/servers/{str(guild.id)}/config.json"):
        try:
            os.makedirs(f"./data/servers/{str(guild.id)}/")
            open(f'./data/servers/{str(guild.id)}/config.json', 'a').close()
        except OSError as e:
            if e.errno != e.errno.EEXIST:
                raise
    bot.serverconfig = pyson.Pyson(f'data/servers/{str(guild.id)}/config.json')
    bot.serverconfig.data = {
        "albums": {},
        "config": {
            "admins": [],
            "prefix": "."
        }
    }
    bot.serverconfig.save()
Ejemplo n.º 17
0
    async def leaderboard(self, ctx):
        l_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-leaderboard')
        while True:
            async for message in l_channel.history():
                await message.delete()
            async with l_channel.typing():
                self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.message.guild.id)}.json')
                self.users = self.bot.server.data.get('users')
                leaderboard = sorted(self.users, key=lambda x: self.users[x]['points'], reverse=True)
                leaderboard = list(enumerate(leaderboard))
                embed = discord.Embed(colour=discord.Colour(0x278d89))
                embed.set_thumbnail(url='https://cgg.website/lb.png')
                players_list = ''
                points_list = ''
                for place, entry in leaderboard[:10]:
                    user_points = self.users[entry]['points']
                    player = await self.bot.get_user_info(entry)
                    players_list += f'**#{place+1}** {player.name}\n'
                    points_list += f'{user_points}\n'

                embed.add_field(name='Players', value=players_list)
                embed.add_field(name='Points', value=points_list)
            await l_channel.send(embed=embed)
            await asyncio.sleep(1800)
Ejemplo n.º 18
0
 async def remove_points(self, points, user,  ctx):
     self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
     old_points = self.bot.server.data.get('users').get(str(user)).get('points')
     self.bot.server.data['users'][str(user)]['points'] = int(old_points) - points
     self.bot.server.save()
Ejemplo n.º 19
0
 def __init__(self, bot):
     self.bot = bot
     self.bot.qa = pyson.Pyson('data/jellybot/qa.json')
     self.timer = True
Ejemplo n.º 20
0
    async def use(self, ctx, emoji: discord.Emoji):
        '''use <item>
        use any item from with the store.
        '''
        events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.message.guild.id)}.json')
        users = self.bot.server.data.get('users')

        itemlist = self.bot.items.data.get('items')

        if isinstance(emoji, discord.Emoji):
            emoji = emoji.name

        list_items = []
        for item in itemlist:
            list_items.append(item)

        if emoji not in list_items:
            await ctx.send('Thats not an item')
            return

        if emoji is None:
            await ctx.send('you didn\'t try to use anything')
            return

        if emoji in list_items:
            above = self.bot.items.data.get('items').get(emoji).get('above')
            below = self.bot.items.data.get('items').get(emoji).get('below')
            cost = self.bot.items.data.get('items').get(emoji).get('cost')
            target = self.bot.items.data.get('items').get(emoji).get('target')
            value = self.bot.items.data.get('items').get(emoji).get('value')
            amount = self.bot.server.data.get('users').get(str(ctx.message.author.id)).get('itemlist').get(emoji)
            description = self.bot.items.data.get('items').get(emoji).get('description')

            if amount == 0 or amount is None:
                await ctx.send(f'you have no {emoji} to use')
                return

            if cost is 5:
                embed = discord.Embed(colour=discord.Colour(0x00bcd4),
                                      description=f'{ctx.message.author.name} used {emoji} : "{description}"')
                await events_channel.send(embed=embed)
            if cost is 15:
                embed = discord.Embed(colour=discord.Colour(0x1976d2),
                                      description=f'{ctx.message.author.name} used {emoji} : "{description}"')
                await events_channel.send(embed=embed)
            if cost is 30:
                embed = discord.Embed(colour=discord.Colour(0x1a237e),
                                      description=f'{ctx.message.author.name} used {emoji} : "{description}"')
                await events_channel.send(embed=embed)

            leaderboard = sorted(users, key=lambda x: users[x]['points'], reverse=True)
            position = leaderboard.index((str(ctx.message.author.id)))
            get_emoji = discord.utils.get(self.bot.emojis, name=emoji)
            if target is None:
                if above is True:
                    if position is 0:
                        await ctx.send(f'You are in position {position+1}, you can\'t use this item')
                        return

                    else:
                        points_above = self.bot.server.data.get('users').get(leaderboard[position - 1]).get('points')
                        new_points_above = int(points_above) + int(value)
                        if new_points_above <= 0:
                            new_points_above = int(0)
                        self.bot.server.data['users'][leaderboard[position - 1]]['points'] = int(new_points_above)
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xc62828),
                                              description=f'{ctx.message.author.name}\'s {get_emoji} just hit '
                                                          f'<@{leaderboard[position-1]}>! They now have {new_points_above} points!')
                        await events_channel.send(embed=embed)
                await self.remove_item(ctx.message.author.id, emoji, amount, ctx)

                if below is True:
                    if position + 1 == len(users):
                        await ctx.send(f'You are in position {position+1}(last place) you can\'t use this item')
                        return

                    else:
                        points_below = self.bot.server.data.get('users').get(leaderboard[position + 1]).get('points')
                        new_points_below = int(points_below) + int(value)
                        if new_points_below <= 0:
                            new_points_below = int(0)
                        self.bot.server.data['users'][leaderboard[position + 1]]['points'] = int(new_points_below)
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xc62828),
                                              description=f'{ctx.message.author.name}\'s {get_emoji} just hit '
                                                          f'<@{leaderboard[position+1]}>! They now have {new_points_below} points!')
                        await events_channel.send(embed=embed)
                        return

            if target is not None:
                if target == "random":
                    if emoji == "ink":
                        await self.item_timer(ctx.message.author.id, emoji, ctx)
                        await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                        return

                    if emoji == "sprinkler":
                        await self.item_timer(ctx.message.author.id, emoji, ctx)
                        await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                        return

                    if emoji == "boo":
                        await self.item_timer(ctx.message.author.id, emoji, ctx)
                        return

                    else:
                        leaderboard = sorted(users, key=lambda x: users[x]['points'], reverse=True)
                        pick_random_user = random.choice(leaderboard)

                        if pick_random_user == ctx.message.author.id:
                            while pick_random_user == ctx.message.author.id:
                                pick_random_user = random.choice(leaderboard)

                        points_old = self.bot.server.data.get('users').get(pick_random_user).get('points')
                        new_points_random = int(points_old) + int(value)

                        if new_points_random <= 0:
                            new_points_random = int(0)
                        self.bot.server.data['users'][pick_random_user]['points'] = int(new_points_random)
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xc62828),
                                              description=f'{ctx.message.author.name}\'s {get_emoji} hit '
                                                          f'<@{pick_random_user}>! They now have {new_points_random} points!')
                        await events_channel.send(embed=embed)
                        await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                        return

                if target == "all":
                    await ctx.send(f'target is {value} {target}')
                    return

                if target == "self":
                    points_old_self = self.bot.server.data.get('users').get(str(ctx.message.author.id)).get('points')
                    value = self.bot.items.data.get('items').get(emoji).get('value')
                    new_points_self = points_old_self + value
                    self.bot.server.data['users'][str(ctx.message.author.id)]['points'] = int(new_points_self)
                    self.bot.server.save()
                    embed = discord.Embed(colour=discord.Colour(0xc62828),
                                          description=f'{ctx.message.author.name}\'s used {get_emoji} and gained '
                                                      f'{value} points, for a total of {new_points_self} points.')
                    await events_channel.send(embed=embed)
                    await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                    return

                if target == "steal":
                    user_list = []
                    for user in users:
                        user_list.append(user)

                    target = None
                    while not target:
                        target = random.choice(user_list)
                        items = self.bot.server.data.get('users').get(target).get('itemlist')
                        if target == ctx.message.author.id:
                            target = None
                        if len(items) == 0:
                            target = None

                    item_list = []
                    targets_items = self.bot.server.data.get('users').get(target).get('itemlist')
                    for item in targets_items:
                        item_list.append(item)
                    item_to_steal = random.choice(item_list)

                    amount_item_target = self.bot.server.data.get('users').get(target).get('itemlist').get(item_to_steal)
                    new_amount_item_target = amount_item_target - 1
                    if new_amount_item_target == 0:
                        self.bot.server.data['users'][target]['itemlist'].pop(item_to_steal, None)
                    self.bot.server.save()
                    player_items = self.bot.server.data.get('users').get(ctx.message.author.id).get('itemlist')
                    player_items_list = []
                    for item in player_items:
                        player_items_list.append(item)

                    if item_to_steal in player_items_list:
                        amount = self.bot.server.data.get('users').get(ctx.message.author.id).get('itemlist').get(item_to_steal)
                        new_amount = amount + 1
                        self.bot.server.data['users'][ctx.message.author.id]['itemlist'][item_to_steal] = new_amount
                    self.bot.server.save()

                    if item_to_steal not in player_items_list:
                        self.bot.server.data['users'][ctx.message.author.id]['itemlist'][item_to_steal] = 1
                    self.bot.server.save()

                    value = self.bot.items.data.get('items').get(emoji).get('value')
                    if value > 0:
                        get_points = self.bot.server.data.get('users').get(ctx.message.author.id).get('points')
                        new_points = get_points + value
                        self.bot.server.data['users'][ctx.message.author.id]['points'] = new_points
                    self.bot.server.save()
                    await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                    name = self.bot.server.data.get('items').get(item_to_steal).get('name')
                    embed = discord.Embed(colour=discord.Colour(0xc62828),
                                          description=f'{ctx.message.author.name}\'s {get_emoji} hit '
                                                      f'<@{target}> and stole {name}!')
                    await events_channel.send(embed=embed)

                if target == "targeted":
                    mention_list = []
                    for mention in ctx.message.mentions:
                        mention_list.append(mention.id)

                    if len(mention_list) < 1:
                        await ctx.send('you need to include a mention')
                        return

                    if len(mention_list) >= 2:
                        await ctx.send('you should include only one mention')
                        return

                    if mention_list[0] == ctx.message.author.id:
                        await ctx.send('you cant use it on yourself....')
                        return

                    if len(mention_list) == 1:
                        await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                        target = mention_list[0]
                        points_old = self.bot.server.data.get('users').get(target).get('points')
                        new_points_target = int(points_old) + int(value)
                        if new_points_target <= 0:
                            new_points_target = int(0)
                        self.bot.server.data['users'][target]['points'] = int(new_points_target)
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xc62828),
                                              description=f'{ctx.message.author.name}\'s {get_emoji} just hit <@{target}>!'
                                                          f' They now have {new_points_target} points!')
                        await events_channel.send(embed=embed)
                        return

                if target == "top":
                    if position == 0:
                        await ctx.send('you cant use this, you are in first')
                        return
                    await self.remove_item(ctx.message.author.id, emoji, amount, ctx)
                    leaderboard = sorted(users, key=lambda x: users[x]['points'], reverse=True)
                    points_old = self.bot.server.data.get('users').get(leaderboard[0]).get('points')
                    new_points = points_old + value
                    self.bot.server.data['users'][leaderboard[0]]['points'] = int(new_points)
                    self.bot.server.save()
                    embed = discord.Embed(colour=discord.Colour(0xc62828),
                                          description=f'{ctx.message.author.name}\'s {get_emoji} just hit '
                                                      f'<@{leaderboard[0]}>! They now have {new_points} points!')
                    await events_channel.send(embed=embed)
                    return
        else:
            await ctx.send('shrug')
            return
Ejemplo n.º 21
0
 def __init__(self, bot):
     self.bot = bot
     self.bot.items = pyson.Pyson('data/jellybot/items.json')
Ejemplo n.º 22
0
    bot.startup_extensions = []
    path = Path('./cogs')
    for dirpath, dirnames, filenames in os.walk(path):
        if dirpath.strip('./') == str(path):
            for cog in filenames:
                if cog.endswith('.py'):
                    extension = 'cogs.' + cog[:-3]
                    bot.startup_extensions.append(extension)

    if __name__ == "__main__":
        for extension in bot.startup_extensions:
            try:
                bot.load_extension(extension)
                print('Loaded {}'.format(extension))
            except Exception as e:
                exc = '{}: {}'.format(type(e).__name__, e)
                print('Failed to load extension {}\n{}'.format(extension, exc))


#create an aiohttp session that cogs can use <3 stroup
async def create_aiohttp():
    bot.aiohttp = aiohttp.ClientSession()


bot.config = pyson.Pyson('data/config/startup.json')
load_extensions()
bot.loop.create_task(create_aiohttp())
bot.run(bot.config.data.get('config').get('discord_token'),
        bot=True,
        reconnect=True)
Ejemplo n.º 23
0
    async def pickone(self, ctx, *, album_name: str = None):
        '''pickone (Optional album name) - picks a random image from the album.
        ex; .pickone a phone
        If only one album exists you do not provide an album name.
        '''
        if len(self.bot.serverconfig.data.get('albums')) is 0:
            await ctx.send('You should probably add an album first..')
            return

        content = self.bot.serverconfig.data.get('config').get('content')
        title = self.bot.serverconfig.data.get('config').get('title')
        if content is None and title is None:
            content = 'You asked me to pick a picture...'
            title = 'I Chose...'

        if not album_name:
            if len(self.bot.serverconfig.data.get('albums')) >= 2:
                await ctx.send('Seems you forgot to provide an album name!')
                return

            elif len(self.bot.serverconfig.data.get(
                    'albums')) == 1:  #will swap this to local storage soon.
                await ctx.message.add_reaction(
                    discord.utils.get(self.bot.emojis, name='check'))
                try:
                    self.bot.serverid = f'{ctx.guild.id}'
                    self.bot.serveralbum = pyson.Pyson(
                        f'data/servers/{self.bot.serverid}/config.json')
                    tail = list(
                        self.bot.serveralbum.data.get(
                            'albums').values())[0].split('/')[4]
                    print(f'serverid: {self.bot.serverid} tail:  {tail}')
                    the_list = list(
                        item.link
                        for item in self.imgur_client.get_album_images(tail))
                    async with self.bot.aiohttp.get(
                            random.choice(the_list)) as resp:
                        link = await resp.read()
                        f = discord.File(io.BytesIO(link),
                                         filename="image.png")
                        e = discord.Embed(
                            title=title,
                            colour=discord.Colour(0x278d89),
                        )
                        e.set_image(url=f'''attachment://image.png''')
                        await ctx.send(file=f, embed=e, content=content)

                except Exception as e:
                    print(f'{e} - single album')
                    print(
                        f"albums = {list(self.bot.serverconfig.data.get('albums'))}"
                    )
                    print(
                        f"length = {len(list(self.bot.serverconfig.data.get('albums')))}"
                    )
                    for album in list(
                            self.bot.serverconfig.data.get('albums')):
                        print(
                            f"name: {album} link: {self.bot.serverconfig.data.get('albums').get(album)}"
                        )
                    if isinstance(e, ImgurClientError):
                        print(f'{e.error_message}')
                        await ctx.send(f'{e.error_message}')
                    elif not isinstance(e, ImgurClientError):
                        await ctx.send(
                            'There was an issue processing this command.')

            elif not self.bot.serverconfig.data.get('albums'):
                await ctx.send('It doesnt seem that you have added an ablum.')

        elif album_name:
            if album_name.lower() in self.bot.serverconfig.data.get('albums'):
                await ctx.message.add_reaction(
                    discord.utils.get(self.bot.emojis, name='check'))
                try:
                    self.bot.serveridmulti = f'{ctx.guild.id}'
                    self.bot.serveralbummulti = pyson.Pyson(
                        f'data/servers/{self.bot.serveridmulti}/config.json')
                    tail = self.bot.serveralbummulti.data.get('albums').get(
                        album_name.lower()).split('/')[4]
                    the_list = list(
                        item.link
                        for item in self.imgur_client.get_album_images(tail))
                    async with self.bot.aiohttp.get(
                            random.choice(the_list)) as resp:
                        link = await resp.read()
                        f = discord.File(io.BytesIO(link),
                                         filename="image.png")
                        e = discord.Embed(
                            title=title,
                            colour=discord.Colour(0x278d89),
                        )
                        e.set_image(url=f'''attachment://image.png''')
                        await ctx.send(file=f, embed=e, content=content)

                except Exception as e:
                    print(f'{e} - multialbum')
                    print(f'message = {ctx.message.content}')
                    print(
                        f"albums = {list(self.bot.serverconfig.data.get('albums'))}"
                    )
                    for album in list(
                            self.bot.serverconfig.data.get('albums')):
                        print(
                            f"name: {album} link: {self.bot.serverconfig.data.get('albums').get(album)}"
                        )
                    if isinstance(e, ImgurClientError):
                        print(f'{e.error_message}')
                        await ctx.send(f'{e.error_message}')
                    elif not isinstance(e, ImgurClientError):
                        await ctx.send(
                            'There was an issue processing this command.')

            elif album_name.lower() not in self.bot.serverconfig.data.get(
                    'albums'):
                await ctx.send(
                    f'I couldnt find an album by the name of "{album_name}"')
Ejemplo n.º 24
0
    async def buy(self, ctx, message: str = None):
        '''buy [category] - choices are weak, skilled and frantic
        eg; buy weak
        '''
        self.bot.server = pyson.Pyson(f'data/jellybot/servers/{str(ctx.guild.id)}.json')
        events_channel = discord.utils.get(ctx.message.guild.channels, name='jelly-events')
        item_list = ['weak', 'skilled', 'frantic']

        if message is None:
            await ctx.send('Categories are weak, skilled, and frantic.')
            return

        message = message.lower()

        weak_items = []
        skilled_items = []
        frantic_items = []
        for item in self.bot.items.data.get('items'):
            cost = self.bot.items.data.get('items').get(item).get('cost')
            if cost is 5:
                weak_items.append(item)
            if cost is 15:
                skilled_items.append(item)
            if cost is 30:
                frantic_items.append(item)
        if self.bot.server.data.get('users').get(str(ctx.author.id)).get('points') < cost:
            await ctx.send('you dont have enough points to buy that')
            return

        if message in item_list:
            weak_recieve = random.choice(weak_items)
            skilled_recieve = random.choice(skilled_items)
            frantic_recieve = random.choice(frantic_items)

            if message == 'weak':
                item_recieved = weak_recieve

            if message == 'skilled':
                item_recieved = skilled_recieve

            if message == 'frantic':
                item_recieved = frantic_recieve

            name = self.bot.items.data.get('items').get(item_recieved).get('name')

            player_inventory = self.bot.server.data.get('users').get(str(ctx.author.id)).get('itemlist')
            amount_to_add = []
            for item in player_inventory:
                get_amount = self.bot.server.data.get('users').get(str(ctx.author.id)).get('itemlist').get(item)
                amount_to_add.append(int(get_amount))

            if len(amount_to_add) == 0:
                self.bot.server.data['users'][(str(ctx.author.id))]['itemlist'][item_recieved] = 1
                self.bot.server.save()
                embed = discord.Embed(colour=discord.Colour(0xb2ff59),
                                      description=f'{ctx.message.author.name} you recieved {name}')
                await events_channel.send(embed=embed)
                await self.remove_points(cost, ctx.author.id, ctx)
                return

            else:
                total = 0
                for item in amount_to_add:
                    total = int(total) + int(item)

                if total >= 3:
                    embed = discord.Embed(colour=discord.Colour(0xb2ff59),
                                          description=f'{ctx.message.author.name} you have too many items already, '
                                                      f'please use one first.')
                    await events_channel.send(embed=embed)
                    return

                else:
                    get_player_inventory = self.bot.server.data.get('users').get((str(ctx.author.id))).get('itemlist')
                    if item_recieved in get_player_inventory:
                        get_current_amount = self.bot.server.data.get('users').get((str(ctx.author.id))).get('itemlist').get(
                            item_recieved)
                        new_value = get_current_amount + 1
                        self.bot.server.data['users'][(str(ctx.author.id))]['itemlist'][item_recieved] = new_value
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xb2ff59),
                                              description=f'{ctx.message.author.name} you recieved {name}')
                        await events_channel.send(embed=embed)
                        await self.remove_points(cost, ctx.author.id, ctx)
                        return

                    else:
                        self.bot.server.data['users'][(str(ctx.author.id))]['itemlist'][item_recieved] = 1
                        self.bot.server.save()
                        embed = discord.Embed(colour=discord.Colour(0xb2ff59),
                                              description=f'{ctx.message.author.name} you recieved {name}')
                        await events_channel.send(embed=embed)
                        await self.remove_points(cost, ctx.author.id, ctx)
                        return

        else:
            await ctx.send('item categories are weak, skilled and frantic.')
            return
Ejemplo n.º 25
0
 def __init__(self, bot):
     self.bot = bot
     self.bot.pomo = pyson.Pyson('data/pomodoro/data.json')