示例#1
0
    def warlog_infomation(self):
        get_all_post = self.get_all_post
        post_response_content = get_all_post['result_data']['items']

        for item in post_response_content:
            commment_count = item['comment_count']
            content = item['content']
            post_key = item['post_key']

            split_content = content.split(' ')
            clan_tag = ''.join(split_content[1:]).strip('#')

            if '!warlog' in split_content and commment_count == 0:

                if clan_tag == '':
                    write_comment(
                        comment_body=
                        f"Invalid Commmand: {emoji.emojize(':red_circle:')}",
                        post_key=post_key)

                else:
                    write_comment(comment_body=
                                  f"Fatching Data: {emoji.emojize(':dizzy:')}",
                                  post_key=post_key)
                    warlog_response_content = coc_request(
                        f'/clans/%23{clan_tag}/warlog?limit=2')['items']

                    warlog_result = ''

                    for warlog in warlog_response_content:
                        warlog_result = warlog_result + f"{warlog['clan']['name']} VS {warlog['opponent']['name']}"

                    write_post(post_content=warlog_result)
示例#2
0
    def random_joke_generator(self):
        get_all_post = self.get_all_post
        post_response_content = get_all_post['result_data']['items']

        for item in post_response_content:
            commment_count = item['comment_count']
            content = item['content']
            post_key = item['post_key']

            if '!joke' in content and commment_count == 0:
                write_comment(
                    comment_body=
                    f"{get_random_joke()['setup']}\n{get_random_joke()['punchline']}",
                    post_key=post_key)
    def help_information(self):
        get_all_post = self.get_all_post
        post_response_content = get_all_post['result_data']['items']

        for item in post_response_content:
            commment_count = item['comment_count']
            content = item['content']
            post_key = item['post_key']

            if '!help' in content and commment_count == 0:
                write_comment(
                    comment_body=f'Here are the list of bot commands:\n'
                    f'!clan -> Clan Information\n'
                    f'!player -> Player Infomation\n'
                    f'!warlog -> Warlog Infomation\n'
                    f'!joke -> Tells a random joke',
                    post_key=post_key)
    def clan_infomation(self):
        get_all_post = self.get_all_post
        post_response_content = get_all_post['result_data']['items']

        for item in post_response_content:
            commment_count = item['comment_count']
            content = item['content']
            post_key = item['post_key']

            split_content = content.split(' ')
            clan_tag = ''.join(split_content[1:]).strip('#')

            if '!clan' in split_content and commment_count == 0:

                if clan_tag == '':
                    write_comment(comment_body=f"Invalid Commmand: {emoji.emojize(':red_circle:')}", post_key=post_key)

                else:
                    write_comment(comment_body=f"Fatching Data: {emoji.emojize(':dizzy:')}", post_key=post_key)
                    clan_response_content = coc_request(f'/clans/%23{clan_tag}')
                    write_post(post_content=f"Clan Name: {clan_response_content['name']} - {clan_response_content['tag']}\n"
                                            f"Clan Points: {clan_response_content['clanPoints']}{emoji.emojize(':trophy:')}")