Exemplo n.º 1
0
    async def _request_help_from_audience(self):
        if self.arg != Cogs.Game.audience:
            return

        if self.user_id not in self.bot.games.keys():
            await self.ctx.send(Reply.not_in_game(self.user_id))
            return True

        player_game = self.bot.games[self.user_id]
        if not player_game.audience:
            await self.ctx.send(Reply.used_audience(self.user_id))

            embed = JokersEmbed(player_game.user.name,
                                player_game.user.avatar_url,
                                player_game.jokers_left())
            await self.ctx.send(embed=embed)
            return True

        msg = await self.ctx.send(Reply.audience_help(30))
        player_game.audience = False
        player_game.audience_channel = self.ctx.channel

        player_game.waiting_audience_help = True
        await self._count_seconds_down_audience(player_game, msg)

        if player_game.waiting_audience_help:
            audience_data = player_game.get_audience_votes()
            embed = AudienceEmbed(**audience_data)
            await self.ctx.send(embed=embed)

        player_game.waiting_audience_help = False
        await msg.add_reaction(Emoji.clock)
Exemplo n.º 2
0
    async def new_game(self, ctx, *args):
        '''
        Creates new Game.
        Add it to the bot games (dictionary).
        Key - string of the user ID
        Value - instance of the bot.core.game.Game class
        '''
        if not args:
            self.arg = 'общо'
        else:
            self.arg = args[0].upper()

        self.ctx = ctx
        self._get_player()

        if self.player_id in self.bot.games.keys():
            await ctx.send(Reply.not_finished(self.player_id))
            return

        if ctx.channel in [g.channel for g in self.bot.games.values()]:
            await ctx.send(Reply.another_game_in_channel(self.player_id))
            return

        await self._create_new_game()
        await self._send_first_question()
Exemplo n.º 3
0
    def __init__(self, uptime, python_version, discord_version, stars, forks,
                 issues, connected_servers, total_members, pc, cpu_use, ram,
                 ram_tot, hdd, hdd_tot):
        super().__init__(color=Color.info)

        uptime = strftime('%H hours %M mins %S secs', gmtime(uptime))

        self.set_author(name=Reply.github_repo(stars, forks, issues),
                        url=Link.github_repo,
                        icon_url=Link.github_icon)
        self.add_field(
            name='🤖 Бот:',
            value=
            f'**Uptime**: {uptime}\n**Сървъри**: {connected_servers}\n**Потребители**: {total_members}'
        )
        self.add_field(name=Text.host,
                       value=Reply.system_info(pc.node, pc.system, pc.release,
                                               cpu_use, ram, ram_tot, hdd,
                                               hdd_tot),
                       inline=False)
        self.add_field(name=Text.used_technologies,
                       value=Reply.used_tech(python_version, discord_version),
                       inline=False)
        self.add_field(name=Text.author, value=Text.me, inline=False)
        self.add_field(name=Text.top_contributors,
                       value=Text.contributors,
                       inline=False)
Exemplo n.º 4
0
    def __init__(
        self,
        player: str,
        player_thumbnail: str,
        question: str,
        question_leva: int,
        question_level: int,
        answers: dict,
        color: int,
        author: str,
        author_thumbnail: str,
    ):
        super().__init__(title=question, color=color)

        self.set_author(name=Reply.game_title(question_level, player,
                                              question_leva),
                        icon_url=player_thumbnail)

        for key in answers:
            self.add_field(name=Reply.choice(key, answers[key]),
                           value=Text.invisible,
                           inline=False)

        if author_thumbnail:
            self.set_footer(text=Reply.question_added_by(author),
                            icon_url=author_thumbnail)
        else:
            self.set_footer(text=Reply.question_added_by(author))
Exemplo n.º 5
0
    def __init__(self, target, authors_n):
        super().__init__(color=Color.top)
        title = what = str()

        if target == 'authors':
            title = Text.top_authors
            what = Text.added_questions
        elif target == 'players':
            what = Text.money
            title = Text.top_players

        self.set_author(name=title, icon_url=Link.leader_board_icon)

        for i in range(len(authors_n)):
            item = authors_n[i]
            if i == 0:
                self.add_field(name=Reply.first_place(i + 1, item[0], item[1],
                                                      what),
                               value=Text.invisible,
                               inline=False)
            elif i == 1:
                self.add_field(name=Reply.sec_place(i + 1, item[0], item[1],
                                                    what),
                               value=Text.invisible,
                               inline=False)
            elif i == 2:
                self.add_field(name=Reply.third_place(i + 1, item[0], item[1],
                                                      what),
                               value=Text.invisible,
                               inline=False)
            else:
                self.add_field(name=Reply.other_place(i + 1, item[0], item[1],
                                                      what),
                               value=Text.invisible,
                               inline=False)
Exemplo n.º 6
0
    def __init__(self):
        super().__init__(color=Color.commands)
        self.add_field(name=Text.main_commands,
                       value=Reply.list_general_commands(P))
        self.add_field(name=Text.statistics, value=Reply.list_stat_commands(P))

        self.add_field(name=Text.game_commands,
                       value=Reply.list_game_commands(P))
Exemplo n.º 7
0
    async def _create_new_game(self):
        # Create new Game and bind it to the user_id in the queue
        self.bot.games[self.player_id] = Game(self.player, self.ctx.channel,
                                              self.arg, self.bot.time)
        self.bot.games[self.player_id].ctx = self.ctx

        await self.ctx.send(Reply.start_game(self.player_id))
Exemplo n.º 8
0
 async def _count_seconds_down_audience(player_game, message):
     for i in range(29, -1, -1):
         # count seconds
         await asyncio.sleep(1)
         if not player_game.waiting_audience_help:
             break
         await message.edit(content=Reply.audience_help(i))
Exemplo n.º 9
0
 async def _user_not_in_game(self) -> bool:
     """
     Returns True if the user is not playing game yet.
     """
     if self.user_id not in self.bot.games.keys():
         await self.ctx.send(Reply.not_in_game(self.user_id))
         return True
Exemplo n.º 10
0
    async def terminate(self, ctx):
        self.user_id = str(ctx.author.id)

        if self.user_id not in self.bot.games.keys():
            await ctx.send(Reply.not_in_game(self.user_id))
            return

        game = self.bot.games[self.user_id]
        money = game.return_money(wrong_answer=False)
        time = self.bot.time - game.start

        await game.last_message.delete()
        save_player(str(game.user.id), money, time)

        del self.bot.games[self.user_id]
        await ctx.send(Reply.end_game(self.user_id, money))
Exemplo n.º 11
0
    async def _take_player_answer(self):
        """
        Takes player answer.
        Asks new question - if the answer is correct.
        Terminates the game - if the answer is wrong.
        """
        player = self.user_id
        game = self.bot.games[player]
        # get the game of the player

        await asyncio.sleep(0.5)
        answer = self.ctx.message.content[1:].upper()
        # take the letter

        if game.correct_answer(answer):
            await self._right_answer()

            await asyncio.sleep(1.5)
            question_data = self.bot.games[player].ask()
            embed = QuestionEmbed(**question_data)

            await game.last_embed.delete()

            game.last_question = question_data
            game.last_embed = await self.ctx.send(embed=embed)

            if game.waiting_friend_help:
                game.waiting_friend_help = False

            if game.waiting_audience_help:
                game.waiting_audience_help = False

        else:
            await self._wrong_answer()

            del self.bot.games[player]
            player_name = Reply.user_name(game.user.name,
                                          game.user.discriminator)
            money = game.return_money()

            if money:
                save_player_money(player_name, money)

            await asyncio.sleep(1.5)
            await game.last_embed.delete()
            await self.ctx.send(Reply.end_game(player, money))
Exemplo n.º 12
0
    async def terminate(self, ctx):
        self.user_id = str(ctx.author.id)

        if self.user_id not in self.bot.games.keys():
            await ctx.send(Reply.not_in_game(self.user_id))
            return

        game = self.bot.games[self.user_id]
        player = Reply.user_name(game.user.name, game.user.discriminator)
        money = game.return_money(wrong_answer=False)

        await game.last_embed.delete()
        if money:
            save_player_money(player, money)

        del self.bot.games[self.user_id]
        await ctx.send(Reply.end_game(self.user_id, money))
Exemplo n.º 13
0
    async def cut_2_answers(self, ctx):
        self.user_id = str(ctx.author.id)

        if self.user_id not in self.bot.games.keys():
            await ctx.send(Reply.not_in_game(self.user_id))
            return

        game = self.bot.games[self.user_id]

        if game.fifty:
            game.remove_2_choices()
            game.last_embed = QuestionEmbed(**game.last_question)

            await game.last_message.edit(embed=game.last_embed)
            game.fifty = False
        else:
            await ctx.send(Reply.used_50(self.user_id))
            embed = JokersEmbed(game.user.name, game.user.avatar_url,
                                game.jokers_left())
            await ctx.send(embed=embed)
Exemplo n.º 14
0
 async def _count_seconds_down_friend(
     player_game,
     helper_name,
     message,
 ):
     for i in range(29, -1, -1):
         # count seconds
         await asyncio.sleep(1)
         if not player_game.waiting_friend_help:
             break
         await message.edit(content=Reply.friend_help(helper_name, i))
Exemplo n.º 15
0
    def __init__(
        self,
        player: str,
        player_thumbnail: str,
        image_url: str,
    ):
        color = 0x1b87e7
        super().__init__(color=color)

        self.set_author(name=Reply.game_of(player), icon_url=player_thumbnail)
        self.set_image(url=image_url)
Exemplo n.º 16
0
    async def jokers(self, ctx):
        self.user_id = str(ctx.author.id)

        if self.user_id not in self.bot.games.keys():
            await ctx.send(Reply.not_in_game(self.user_id))
            return

        player_id = self.user_id

        game = self.bot.games[player_id]
        embed = JokersEmbed(game.user.name, game.user.avatar_url,
                            game.jokers_left())
        await ctx.send(embed=embed)
Exemplo n.º 17
0
    def __init__(self, python_version, discord_version, stars, forks, issues,
                 connected_servers, total_members, pc, cpu_use, ram):
        super().__init__(color=Color.info)

        self.set_author(name=Reply.github_repo(stars, forks, issues),
                        url=Link.github_repo,
                        icon_url=Link.github_icon)
        self.add_field(name=Text.discord_servers,
                       value=str(connected_servers),
                       inline=True)
        self.add_field(name=Text.users, value=str(total_members), inline=True)
        self.add_field(name=Text.host,
                       value=Reply.system_info(pc.node, pc.system, pc.release,
                                               cpu_use, ram),
                       inline=False)
        self.add_field(name=Text.used_technologies,
                       value=Reply.used_tech(python_version, discord_version),
                       inline=False)
        self.add_field(name=Text.author, value=Text.me, inline=False)
        self.add_field(name=Text.top_contributors,
                       value=Text.contributors,
                       inline=False)
Exemplo n.º 18
0
    def __init__(
        self,
        player: str,
        player_thumbnail: str,
        question_level: int,
        count_votes: int,
        votes: dict,
        color: int,
    ):
        super().__init__(color=color)

        self.set_author(name=Reply.help_from_audience(player, question_level),
                        icon_url=player_thumbnail)
        for vote in votes:
            lines = votes[vote] * '|'
            if not lines:
                lines = Text.invisible

            self.add_field(name=Reply.letter_percent(vote, votes[vote]),
                           value=lines,
                           inline=False)

        self.set_footer(text=Reply.total_votes(count_votes))
Exemplo n.º 19
0
    async def _request_help_from_audience(self):
        if self.arg != Cogs.Game.audience:
            return

        if self.user_id not in self.bot.games.keys():
            await self.ctx.send(Reply.not_in_game(self.user_id))
            return True

        player_game = self.bot.games[self.user_id]
        if not player_game.audience:
            await self.ctx.send(Reply.used_audience(self.user_id))

            embed = JokersEmbed(player_game.user.name,
                                player_game.user.avatar_url,
                                player_game.jokers_left())
            await self.ctx.send(embed=embed)
            return True

        player_game.audience_msg = await self.ctx.send(Reply.audience_help(10))
        player_game.audience = False
        player_game.audience_channel = self.ctx.channel
        player_game.start_audience_help = self.bot.time

        player_game.waiting_audience_help = True
Exemplo n.º 20
0
    async def new_game(self, ctx):
        '''
        Creates new Game.
        Add it to the bot games (dictionary).
        Key - string of the user ID
        Value - instance of the bot.core.game.Game class
        '''
        self.ctx = ctx
        self._get_player()

        if self.player_id in self.bot.games.keys():
            await ctx.send(Reply.not_finished(self.player_id))
            return

        await self._create_new_game()
        await self._send_first_question()
Exemplo n.º 21
0
    async def _request_help_from_friend(self):
        if self.user_id not in self.bot.games.keys():
            await self.ctx.send(Reply.not_in_game(self.user_id))
            return

        player_game = self.bot.games[self.user_id]
        helper_id = self._extract_id_from_tag(self.arg)

        if not helper_id:
            await self.ctx.send(Reply.unknown_2_arg(self.user_id))
            return

        if not player_game.friend:
            await self.ctx.send(Reply.used_friend(self.user_id))

            embed = JokersEmbed(player_game.user.name,
                                player_game.user.avatar_url,
                                player_game.jokers_left())
            await self.ctx.send(embed=embed)
            return

        if str(helper_id) == self.user_id:
            await self.ctx.send(Reply.no_yourself(self.user_id))
            return

        if str(helper_id) in self.bot.games.keys():
            await self.ctx.send(Reply.no_player(self.user_id))
            return

        helper = self.bot.get_user(helper_id)
        # get discord.User object of the helper

        if helper.bot:
            await self.ctx.send(Reply.no_bot(self.user_id))
            return

        # Asserts that the helper is not a bot or the player itself
        msg = await self.ctx.send(Reply.friend_help(helper.name, 30))
        player_game.friend = False
        # the joker is gone

        self.bot.helping_friends[str(helper_id)] = self.user_id
        # add the helper to the queue and bind the player id
        player_game.waiting_friend_help = True
        await self._count_seconds_down_friend(player_game, helper.name, msg)
        player_game.waiting_friend_help = False
        await msg.add_reaction(Emoji.clock)
        del self.bot.helping_friends[str(helper_id)]
Exemplo n.º 22
0
    def __init__(
        self,
        player: str,
        player_thumbnail: str,
        helper: str,
        helper_thumbnail: str,
        question_level: int,
        vote: dict,
        color: int,
    ):
        super().__init__(color=color)

        self.set_author(name=Reply.help_from_friend(player, helper,
                                                    question_level),
                        icon_url=player_thumbnail)

        self.add_field(name=str(list(vote.keys())[0]),
                       value=str(list(vote.values())[0]),
                       inline=False)

        self.set_thumbnail(url=helper_thumbnail)
Exemplo n.º 23
0
    async def add_it(self, ctx):
        self.user = self.bot.get_user(ctx.author.id)

        dm = self.user.dm_channel
        if not dm:
            dm = await self.user.create_dm()
        pins = await dm.pins()

        if not len(pins):
            await dm.send('Няма pin-нати съобщения в този чат.')
            return

        pattern = Regex.form

        success = int()
        questions = list()

        for pin in pins:
            content = pin.content
            print(content)
            match = re.search(pattern, content)
            print(match)

            if match:
                success += 1
                await pin.add_reaction(Emoji.thumb_up)
                await pin.unpin()

                adict = match.groupdict()

                for k in adict:
                    if adict[k]:
                        new_item = adict[k].strip()
                    else:
                        new_item = None

                    if new_item:
                        adict[k] = new_item
                    else:
                        adict[k] = None

                adict['user'] = Reply.user_name(self.user.name,
                                                self.user.discriminator)
                adict['user_id'] = str(ctx.author.id)
                adict['date'] = str(datetime.datetime.now())
                questions.append(adict)
            else:
                await pin.add_reaction(Emoji.thumb_down)
                await pin.unpin()

        if questions:
            append_to_pending(questions)

        if len(pins) == 1 and success == 0:
            await dm.send('Pin-натото съобщение не отговаря на формата.')
        elif len(pins) == 1:
            await dm.send(
                'Успешно изпратен въпрос. Очаква се преглед от модератор. Ще Ви известим ако въпроса Ви е в игра.'
            )
        elif success == 0:
            await dm.send('Pin-натите съобщения не отговарят на формата.')
        else:
            await dm.send(
                f'{success} от {len(pins)} успешно изпратени въпроса. Очаква се преглед от модератор. Ще Ви известим ако въпросите Ви са в игра.'
            )
Exemplo n.º 24
0
    async def add_it(self, ctx):
        self.user = self.bot.get_user(ctx.author.id)
        self.god = self.bot.get_user(GOD)

        dm = self.user.dm_channel
        if not dm:
            dm = await self.user.create_dm()
        pins = await dm.pins()

        if not len(pins):
            await dm.send(Text.no_pins)
            return

        pattern = Regex.form

        success = int()
        questions = list()

        for pin in pins:
            content = pin.content
            print(content)
            match = re.search(pattern, content)
            print(match)

            if match:
                success += 1
                await pin.add_reaction(Emoji.thumb_up)
                await pin.unpin()

                adict = match.groupdict()

                for k in adict:
                    if adict[k]:
                        new_item = adict[k].strip()
                    else:
                        new_item = None

                    if new_item:
                        adict[k] = new_item
                    else:
                        adict[k] = None

                adict['user'] = Reply.user_name(self.user.name,
                                                self.user.discriminator)
                adict['user_id'] = ctx.author.id
                adict['date'] = str(datetime.datetime.now())
                questions.append(adict)
            else:
                await pin.add_reaction(Emoji.thumb_down)
                await pin.unpin()

        if questions:
            append_to_pending(questions)

        if len(pins) == 1 and success == 0:
            await dm.send(Text.pin_not_inform)
        elif len(pins) == 1:
            await dm.send(Text.success_send)
            await self.god.dm_channel.send('Има добавен въпрос!')
        elif success == 0:
            await dm.send(Text.pins_not_inform)
        else:
            await dm.send(Reply.successfully_send(success, len(pins)))
            await self.god.dm_channel.send('Има добавени въпроси!')
Exemplo n.º 25
0
 async def _create_new_game(self):
     # Create new Game and bind it to the user_id in the queue
     self.bot.games[self.player_id] = Game(self.player)
     await self.ctx.send(Reply.start_game(self.player_id))
     await asyncio.sleep(1)
Exemplo n.º 26
0
    async def change_games_count(self):
        d = self.games.copy()
        for player_id in d:
            game = self.games[player_id]
            diff = self.time - game.start_question

            if diff == SECS - 5:
                await game.last_message.edit(
                    content=f'⏳ **Остават ти 5 секунди!**',
                    embed=game.last_embed)
            elif diff % 10 == 0:
                await game.last_message.edit(
                    content=f'⏳ **Имаш {SECS - diff} секунди**',
                    embed=game.last_embed)

            if self.time - game.start_question == SECS:
                await game.last_message.edit(
                    content=f'⏳ **Изтече ти времето!**',
                    embed=game.last_embed,
                    delete_after=5)
                player = Reply.user_name(game.user.name,
                                         game.user.discriminator)
                money = game.return_money(wrong_answer=True)
                time = self.time - game.start

                save_player(str(game.user.id), money, time)

                await game.ctx.send(Reply.end_game(game.user.id, money))
                del self.games[player_id]

            # check friends help
            if game.waiting_friend_help:
                user = self.get_user(int(game.helper_id))
                if self.time - game.start_friend_help == 5:
                    await game.friend_msg.edit(
                        content=Reply.friend_help(user.name, 5))
                if self.time - game.start_friend_help == 10:
                    game.waiting_friend_help = False

                    await game.friend_msg.edit(
                        content=Reply.friend_help(user.name, 0))
                    await game.friend_msg.add_reaction(Emoji.clock)
                    del self.helping_friends[game.helper_id]

            if not game.add_friend_reaction and \
               not game.waiting_friend_help and \
                   game.start_friend_help:
                await game.friend_msg.add_reaction(Emoji.clock)
                game.add_friend_reaction = True
                try:
                    del self.helping_friends[int(game.helper_id)]
                except:
                    pass

            if game.waiting_audience_help:
                if self.time - game.start_audience_help == 5:
                    await game.audience_msg.edit(content=Reply.audience_help(5)
                                                 )
                if self.time - game.start_audience_help == 10:
                    audience_data = game.get_audience_votes()
                    embed = AudienceEmbed(**audience_data)

                    await game.audience_msg.edit(content=Reply.audience_help(0)
                                                 )
                    await game.audience_channel.send(embed=embed)
                    await game.audience_msg.add_reaction(Emoji.clock)

                    game.waiting_audience_help = False

            if not game.add_audience_reaction and \
               not game.waiting_audience_help and \
                   game.start_audience_help:
                await game.audience_msg.add_reaction(Emoji.clock)
                game.add_audience_reaction = True
Exemplo n.º 27
0
    async def on_reaction_add(self, reaction, user):
        answers_map = {'🇦': 'A', '🇧': 'B', '🇨': 'C', '🇩': 'D'}

        if str(user.id) in self.games.keys() and reaction.emoji in answers_map:
            player = str(user.id)
            game = self.games[player]
            game.answered = True
            # get the game of the player

            # await asyncio.sleep(0.5)
            answer = answers_map[reaction.emoji]
            # take the letter

            if game.correct_answer(answer):
                await self._right_answer(game.ctx)

                if game.question_level == 15:
                    player_name = Reply.user_name(game.user.name,
                                                  game.user.discriminator)
                    money = game.question_amount_map[15]
                    time = self.time - game.start

                    await game.ctx.send(Gif.win)
                    await game.ctx.send(
                        f'<@{game.user.id}> жалко, че не са истински.')

                    save_player(str(game.user.id), money, time)
                    del self.games[player]

                    return

                question_data = self.games[player].ask()
                game.last_embed = QuestionEmbed(**question_data)
                game.start_question = self.time

                game.last_question = question_data
                await game.last_message.edit(delete_after=5)
                game.last_message = await game.ctx.send(
                    content=f'⏳ **Имаш {SECS} секунди**',
                    embed=game.last_embed)

                await self._send_to_nick(game.last_question, game.right_answer)

                await game.last_message.add_reaction('🇦')
                await game.last_message.add_reaction('🇧')
                await game.last_message.add_reaction('🇨')
                await game.last_message.add_reaction('🇩')

                if game.waiting_friend_help:
                    game.waiting_friend_help = False

                if game.waiting_audience_help:
                    game.waiting_audience_help = False
            else:
                await self._wrong_answer(game.ctx)

                player_name = Reply.user_name(game.user.name,
                                              game.user.discriminator)
                money = game.return_money()
                time = self.time - game.start

                save_player(str(game.user.id), money, time)
                del self.games[player]

                await game.last_message.edit(delete_after=5)
                await game.ctx.send(Reply.end_game(player, money))