Esempio n. 1
0
async def on_message(message, secret_context):
    text = message.content[5:]
    if text == "":
        # print the help
        secret_context.bus.emit('secret_command', command='!help hex')
    else:
        # try to parse it as a number first
        try:
            a = int(text)
            embed = utils.simple_embed('hex', hex(a), utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
        except Exception as e:
            # it's a string
            a = str(text)
            if a.startswith("0x"):
                try:
                    a = int(text, 16)
                    embed = utils.simple_embed('hex', hex(a),
                                               utils.random_color())
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
                    return
                except Exception as e:
                    pass
            r = binascii.hexlify(a.encode('utf8'))
            embed = utils.simple_embed('hex', r.decode('utf8'),
                                       utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
Esempio n. 2
0
    def secret_update(self, print_no_update=False, web_update=False):
        if web_update:
            commits = self.secret_context.web_repo.get_commits()
        else:
            commits = self.secret_context.git_repo.get_commits()

        commit = commits[0]
        if not web_update and commit.sha != self.last_commit_sha:
            embed = discord.Embed(title='core update', type='rich',
                                  description='updating core to commit: **' + commit.sha + '**',
                                  color=utils.random_color())
            self.secret_context.bus.emit('secret_send', message=embed)
            # use pipe and shell.. feel free to code a better way
            os.system("git fetch origin master && git reset --h FETCH_HEAD")
            os.system("pip3 install -r requirements.txt")
            self.secret_context.bus.emit('secret_restart')
        elif web_update and commit.sha != self.last_web_commit_sha:
            embed = discord.Embed(title='web update', type='rich',
                                  description='updating web to commit: **' + commit.sha + '**',
                                  color=utils.random_color())
            self.secret_context.bus.emit('secret_send', message=embed)
            # use pipe and shell.. feel free to code a better way
            os.system("cd /var/www/html && git fetch origin master && git reset --h FETCH_HEAD")
        elif print_no_update:
            embed = discord.Embed(title='update', type='rich',
                                  description='nothing new to merge',
                                  color=utils.random_color())
            self.secret_context.bus.emit('secret_send', message=embed)
Esempio n. 3
0
 async def _restart(self):
     print('----------------------------')
     print('secRet bot is now restarting')
     print('----------------------------')
     await self.secret_context.discord_client.send_message(
         self.secret_context.secret_channel,
         embed=utils.simple_embed('restart', 'restarting secRet dBot',
                                  utils.random_color()))
     os.execv(sys.executable, [sys.executable.split("/")[-1]] + sys.argv)
Esempio n. 4
0
async def bot_status(secret_context):
    status = secret_context.handler_status.get_bot_status()
    embed = discord.Embed(title='bot status', type='rich',
                          description='** **',
                          color=utils.random_color())
    embed.set_thumbnail(url=status['icon'])

    embed.add_field(name='time', value=status['now'], inline=True)
    embed.add_field(name='uptime', value=status['uptime'], inline=True)
    await secret_context.discord_client.send_message(
        secret_context.secret_channel, embed=embed)
Esempio n. 5
0
async def on_message(message, secret_context):
    parts = message.content.split(" ")
    if len(parts) < 2:
        # print the help
        secret_context.bus.emit('secret_command', command='!help gif')
    else:
        if parts[1] == 'random':
            r = requests.get('http://api.giphy.com/v1/gifs/random?api_key=' +
                             API_KEY)
            if r.status_code == 200:
                rs = json.loads(r.content.decode('utf8'))
                embed = utils.simple_embed('gif', 'random',
                                           utils.random_color())
                embed.set_image(url=rs['data']['image_url'])
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
        elif parts[1] == 'search':
            try:
                q = str.join(" ", parts[2])
                off = 0
                if len(parts) > 3:
                    try:
                        off = int(parts[3])
                    except Exception as e:
                        pass
                r = requests.get(
                    'http://api.giphy.com/v1/gifs/search?api_key=' + API_KEY +
                    '&q=' + q + '&limit=1&offset=' + str(off))
                if r.status_code == 200:
                    rs = json.loads(r.content.decode('utf8'))
                    for item in rs['data']:
                        embed = utils.simple_embed(item['slug'],
                                                   item['source'],
                                                   utils.random_color())
                        embed.set_image(url=item['images']['original']['url'])
                        await secret_context.discord_client.send_message(
                            message.channel, embed=embed)
            except Exception as e:
                pass
Esempio n. 6
0
 async def on_ready(self):
     print('----------------------------')
     print('secRet bot connected')
     print('----------------------------')
     embed = utils.simple_embed('secRet dBot', 'services initialized',
                                utils.random_color())
     embed.set_author(name='secret',
                      url='http://secret.re',
                      icon_url=utils.ICON)
     embed.set_thumbnail(url=utils.ICON)
     embed.add_field(name="!help", value="initial help")
     embed.add_field(name="!commands", value="available commands")
     await self.secret_context.discord_client.send_message(
         self.secret_context.secret_channel, embed=embed)
Esempio n. 7
0
async def discord_status(secret_context):
    status = secret_context.handler_status.get_discord_status()
    embed = discord.Embed(title='discord status', type='rich',
                          description='** **',
                          color=utils.random_color())
    if status['connected']:
        embed.set_thumbnail(url=status['icon'])
        embed.add_field(name='id', value=status['id'], inline=True)
        embed.add_field(name='name', value=status['name'], inline=True)
        embed.add_field(name='created', value=status['created_at'], inline=True)
        embed.add_field(name='members', value=str(status['members']), inline=True)

    await secret_context.discord_client.send_message(
        secret_context.secret_channel, embed=embed)
Esempio n. 8
0
def enumerate_themes(message, secret_context, index):
    regex = re.compile('wp-content/themes/(.*?)/.*?[css|js].*?ver=([0-9\.]*)')
    match = regex.findall(index.text)
    theme = {}

    for m in match:
        theme_name = m[0]
        theme_name = theme_name.replace('-master', '')
        theme_name = theme_name.replace('.min', '')
        theme_version = m[1]

        if m[0] not in theme.keys():
            theme[m[0]] = m[1]
            with open('secret/api/wordpress/themes.json') as data_file:
                data = json.load(data_file)

            embed = utils.simple_embed(theme_name, theme_version,
                                       utils.random_color())
            if theme_name in data.keys():
                if is_lower(theme_version, data[theme_name]['latest_version'],
                            False):
                    embed.add_field(name='latest version',
                                    value=data[theme_name]['latest_version'],
                                    inline=False)

                for vuln in data[theme_name]['vulnerabilities']:
                    if 'fixed_in' in vuln.keys() and (
                            vuln['fixed_in'] is None or is_lower(
                                theme_version, vuln['fixed_in'], True)):
                        embed.add_field(name=vuln['vuln_type'] + ' | ' +
                                        vuln['title'] + ' (' +
                                        str(vuln['id']) + ')',
                                        value="fixed in %s" % vuln['fixed_in'],
                                        inline=False)
                        for ref_key in vuln['references'].keys():
                            for ref in vuln['references'][ref_key]:
                                if ref_key != 'url':
                                    embed.add_field(
                                        name='reference',
                                        value=ref_key.capitalize() + ' - ' +
                                        ref)
                                else:
                                    embed.add_field(name='reference',
                                                    value=ref)
                secret_context.main_loop.create_task(
                    secret_context.discord_client.send_message(message.channel,
                                                               embed=embed))
Esempio n. 9
0
    async def roll(self, message):
        """
        simple roll accepting max as first arg
        """
        parts = message.content.split(" ")
        max = 100
        if len(parts) > 1:
            try:
                max = int(parts[1])
            except Exception as e:
                pass

        embed = utils.simple_embed('roll',
                                   '**' + str(random.randint(0, max)) + '**',
                                   utils.random_color())
        await self.secret_context.discord_client.send_message(message.channel,
                                                              embed=embed)
Esempio n. 10
0
    async def fetch(self, message, discord_client, package_name):
        try:
            store_info = self.cli.api.details(package_name)

            icon = None
            color = utils.random_color()

            for img in store_info['images']:
                if img['imageType'] == 4:
                    icon = img['url']
                    break
            if icon:
                response = requests.get(icon)
                if response.status_code == 200:
                    if not os.path.exists('files'):
                        os.mkdir('files')
                    with open("files/tmp_gplay_icon.png", 'wb') as f:
                        f.write(response.content)
                    color_thief = ColorThief("files/tmp_gplay_icon.png")
                    dominant_color = color_thief.get_color(quality=1)
                    color = int(utils.rgb_to_hex(dominant_color), 16)

            embed = utils.simple_embed(store_info['title'], store_info['docId'], color)
            if icon:
                embed.set_thumbnail(url=icon)
            embed.add_field(name='author', value=store_info['author'])
            embed.add_field(name='version code', value=str(store_info['versionCode']))
            embed.add_field(name='uploaded', value=store_info['uploadDate'])
            embed.add_field(name='downloads', value=store_info['numDownloads'].replace('downloads', ''))
            embed.add_field(name='rating', value=str(store_info['aggregateRating']['starRating']))
            embed.add_field(name='comments', value=str(store_info['aggregateRating']['commentCount']))
            embed.add_field(name='type', value=store_info['category']['appType'])
            embed.add_field(name='category', value=store_info['category']['appCategory'])
            await discord_client.send_message(message.channel, embed=embed)
        except gplaycli.RequestError as e:
            embed = utils.simple_embed('google play', 'package **' + package_name + '** not found',
                                       discord.Color.red())
            embed.set_thumbnail(url=self.play_icon_url)
            await discord_client.send_message(message.channel, embed=embed)
        except Exception as e:
            embed = utils.simple_embed('google play', 'error on package **' + package_name + '**. ' + str(e),
                                       discord.Color.red())
            embed.set_thumbnail(url=self.play_icon_url)
            await discord_client.send_message(message.channel, embed=embed)
Esempio n. 11
0
async def mongo_status(secret_context):
    status = secret_context.handler_status.get_mongo_status()
    embed = discord.Embed(title='mongo status', type='rich',
                          description='** **',
                          color=utils.random_color())
    embed.set_thumbnail(url=status['icon'])
    embed.add_field(name='host', value=status['host'], inline=True)
    embed.add_field(name='version', value=status['version'], inline=True)
    embed.add_field(name='process', value=status['process'], inline=True)
    embed.add_field(name='pid', value=status['pid'], inline=True)
    embed.add_field(name='db', value=status['db'], inline=True)
    embed.add_field(name='collections', value=str(status['collections']), inline=True)
    embed.add_field(name='objects', value=str(status['objects']), inline=True)
    embed.add_field(name='indexes', value=str(status['indexes']), inline=True)
    embed.add_field(name='sizes', value="-", inline=False)
    embed.add_field(name='storage', value=utils.convert_size(status['storage_size']), inline=True)
    embed.add_field(name='indexes', value=utils.convert_size(status['index_size']), inline=True)
    await secret_context.discord_client.send_message(
        secret_context.secret_channel, embed=embed)
Esempio n. 12
0
    async def search(self, message, discord_client, q):
        results = self.cli.search(q, 3)
        if results is None:
            embed = utils.simple_embed('google play', 'no apps found for: **' + q + '**',
                                       discord.Color.red())
            embed.set_thumbnail(url=self.play_icon_url)
            await discord_client.send_message(message.channel, embed=embed)
        else:
            # remove headers
            results.pop(0)

            embed = utils.simple_embed('google play', 'results for: **' + q + '**', discord.Color.red())
            embed.set_thumbnail(url=self.play_icon_url)
            await discord_client.send_message(message.channel, embed=embed)
            for pkg in results:
                embed = utils.simple_embed(pkg[0], pkg[5], utils.random_color())
                embed.add_field(name='creator', value=pkg[1])
                embed.add_field(name='last update', value=pkg[4])
                embed.add_field(name='downloads', value=pkg[3].replace(' downloads', ''))
                embed.add_field(name='size', value=pkg[2])
                embed.add_field(name='version', value=pkg[6])
                embed.add_field(name='rating', value=pkg[7])
                await discord_client.send_message(message.channel, embed=embed)
Esempio n. 13
0
async def update_vuln_db(message, secret_context):
    if not os.path.exists('secret/api/wordpress'):
        os.mkdir('secret/api/wordpress')

    update_url = "https://data.wpscan.org/"
    update_files = [
        'local_vulnerable_files.xml', 'local_vulnerable_files.xsd',
        'timthumbs.txt', 'user-agents.txt', 'wp_versions.xml',
        'wp_versions.xsd', 'wordpresses.json', 'plugins.json', 'themes.json'
    ]

    embed = utils.simple_embed('wordpress', 'updating vulnerability database',
                               discord.Color.green())
    await secret_context.discord_client.send_message(message.channel,
                                                     embed=embed)
    for f in update_files:
        embed = utils.simple_embed('wordpress', 'downloading %s' % f,
                                   utils.random_color())
        await secret_context.discord_client.send_message(message.channel,
                                                         embed=embed)
        utils.download_raw_file(update_url + f, "secret/api/wordpress/" + f)

    unzip_file("secret/api/wordpress/user-agents.txt")
    unzip_file("secret/api/wordpress/timthumbs.txt")
Esempio n. 14
0
async def help(message, discord_client, cmd_maps, shortcuts_map):
    """
    :param message:
    discord message
    :param discord_client:
    discord client
    :param cmd_maps:
    array with all command maps
    :return:
    """
    parts = message.content.split(" ")
    if len(parts) < 2:
        embed = discord.Embed(
            title='',
            type='rich',
            description=
            "goal is to build me as an automated **bot** with whatever feature "
            "people would like to code. I'll soon run on a virtual"
            " machine with **root** privileges,"
            "but meanwhile, I can already do something:\n\n** **",
            color=discord.Colour.dark_red())
        embed.set_thumbnail(url=utils.ICON)
        embed.set_author(name="secRet", url="https://secret.re")
        embed.add_field(name="!commands",
                        value="something to interact with me",
                        inline=False)
        embed.add_field(name="!devme",
                        value="info and help about coding features",
                        inline=False)
        embed.add_field(name="!rules",
                        value="a world without rules... mhhh chaos",
                        inline=False)
        await discord_client.send_message(message.channel, embed=embed)
    else:
        cmd = parts[1]
        found = False

        if cmd in shortcuts_map:
            cmd = shortcuts_map[cmd]

        for map in cmd_maps:
            if cmd in map:
                found = True
                cmd_object = map[cmd]
                color = utils.random_color()
                embed = discord.Embed(title=cmd,
                                      type='rich',
                                      description=cmd_object['description'],
                                      color=color)
                if 'author' in cmd_object:
                    embed.add_field(name='author',
                                    value=cmd_object['author'],
                                    inline=False)
                await discord_client.send_message(message.channel, embed=embed)
                if 'sub_commands' in cmd_object:
                    embed = discord.Embed(title='sub commands',
                                          type='rich',
                                          description='** **',
                                          color=color)
                    for sub in cmd_object['sub_commands']:
                        description = '** **'
                        if 'description' in sub:
                            description = sub['description']
                        embed.add_field(name='!' + cmd + ' ' + sub['name'],
                                        value=description,
                                        inline=False)
                    await discord_client.send_message(message.channel,
                                                      embed=embed)
                break
        if not found:
            embed = utils.simple_embed('error', 'command not found',
                                       discord.Color.red())
            await discord_client.send_message(message.channel, embed=embed)
Esempio n. 15
0
 async def on_member_remove(self, member):
     embed = utils.simple_embed('Welcome', member.mention + ' has left',
                                utils.random_color())
     await self.secret_context.discord_client.send_message(
         self.secret_context.welcome_channel, embed=embed)
Esempio n. 16
0
async def on_message(message, secret_context):
    parts = message.content.split(" ")
    p_len = len(parts)
    if p_len < 2:
        # print the help
        secret_context.bus.emit('secret_command', command='!help wiki')
    elif p_len > 2:
        cmd = parts[1]
        q = str.join(" ", parts[2:])
        if cmd == 'search':
            r = wikipedia.search(q)
            if len(r) > 0:
                embed = utils.simple_embed('wikipedia',
                                           'search results for: **' + q + '**',
                                           discord.Color.lighter_grey())
                embed.set_thumbnail(url=WIKI_ICON)
                for result in r:
                    embed.add_field(name=result,
                                    value='!wikipedia fetch **' + result +
                                    '**',
                                    inline=False)
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
            else:
                embed = utils.simple_embed('wikipedia',
                                           'no results for: **' + q + '**',
                                           discord.Color.red())
                embed.set_thumbnail(url=WIKI_ICON)
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
        elif cmd == 'fetch':
            try:
                r = wikipedia.page(q)
                color = utils.random_color()
                img = WIKI_ICON
                if len(r.images) > 0:
                    m_img = r.images
                    f_img = None
                    while len(m_img) > 0:
                        img = m_img[0]
                        m_img.pop(0)
                        if str(img).endswith('.png') or str(img).endswith(
                                '.jpg') or str(img).endswith('.jpeg'):
                            f_img = img
                            break

                    if f_img:
                        response = requests.get(img)
                        if response.status_code == 200:
                            if not os.path.exists('files'):
                                os.mkdir('files')
                            with open("files/tmp_wiki_icon.png", 'wb') as f:
                                f.write(response.content)
                            color_thief = ColorThief("files/tmp_wiki_icon.png")
                            dominant_color = color_thief.get_color(quality=1)
                            color = int(utils.rgb_to_hex(dominant_color), 16)
                embed = utils.simple_embed(q, r.summary, color)
                embed.set_thumbnail(url=img)
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
            except wikipedia.PageError as e:
                embed = utils.simple_embed('wikipedia',
                                           'no results for: **' + q + '**',
                                           discord.Color.red())
                embed.set_thumbnail(url=WIKI_ICON)
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
            except wikipedia.DisambiguationError as e:
                embed = utils.simple_embed(
                    'wikipedia', 'no results for: **' + q +
                    '**. Use !wiki search *keywords and '
                    'provide a working page to fetch.', discord.Color.red())
                embed.set_thumbnail(url=WIKI_ICON)
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
Esempio n. 17
0
async def on_message(message, secret_context):
    parts = message.content.split(" ")
    if len(parts) < 2:
        # print the help
        secret_context.bus.emit('secret_command', command='!help cloudsolve')
    else:
        domain = str(parts[1])
        if domain.startswith('http://'):
            domain.replace('http://', '')
        elif domain.startswith('https://'):
            domain.replace('https://', '')
        if not utils.is_valid_domain(domain):
            embed = utils.simple_embed(
                'cloudsolve', ('**%s** is not a valid domain' % domain),
                utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
        elif not uses_cloudflare(domain):
            embed = utils.simple_embed(
                'cloudsolve', ('"%s" is not behind CloudFlare' % domain),
                discord.Color.red())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
        else:
            embed = utils.simple_embed(
                'cloudsolve',
                ('**%s** appear to be behind CloudFlare' % domain),
                discord.Color.green())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
            embed = utils.simple_embed(
                'cloudsolve',
                ('trying to exploit **%s** certificates' % domain),
                utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
            certs = exploit_certificates(domain, secret_context)
            if len(certs) > 0:
                embed = utils.simple_embed(
                    'cloudsolve', ('%d certificates matching **%s** found' %
                                   (len(certs), domain)), utils.random_color())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
                embed = utils.simple_embed(
                    'cloudsolve',
                    ('looking for ipv4 hosts on **%s**' % domain),
                    utils.random_color())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
                hosts = find_ipv4_hosts(certs, secret_context)
                hosts = filter_cloudflare_ips(hosts)

                if len(hosts) is 0:
                    embed = utils.simple_embed('cloudsolve', (
                        '**%s** looks not exploitable. todo: bruteforce domain'
                        % domain), utils.random_color())
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
                else:
                    embed = utils.simple_embed(
                        'cloudsolve', ('%d ipv4 hosts found on **%s**' %
                                       (len(hosts), domain)),
                        utils.random_color())
                    for h in hosts:
                        embed.add_field(name=h, value='ipv4', inline=True)
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
                    origins = find_origins(domain, hosts)
                    embed = utils.simple_embed(
                        'cloudsolve',
                        ('looking for origins on **%s**' % domain),
                        utils.random_color())
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
                    if len(origins) is 0:
                        embed = utils.simple_embed('cloudsolve', (
                            'did not found any origin server for **%s**. todo: bruteforce '
                            'domain' % domain), utils.random_color())
                        await secret_context.discord_client.send_message(
                            message.channel, embed=embed)
                    else:
                        embed = utils.simple_embed(
                            'cloudsolve', ('found %d origins for **%s**' %
                                           (len(origins), domain)),
                            utils.random_color())
                        for o in origins:
                            embed.add_field(name=o[0],
                                            value=o[1],
                                            inline=False)
                        await secret_context.discord_client.send_message(
                            message.channel, embed=embed)
            else:
                embed = utils.simple_embed(
                    'cloudsolve',
                    ('no certificates found for **%s**' % domain),
                    utils.random_color())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
Esempio n. 18
0
async def git(message, secret_context):
    parts = message.content.split(" ")

    if len(parts) < 2:
        await print_git_help(secret_context.bus)
    else:
        if parts[1] == 'commits':
            await get_last_commits(message, secret_context)
        elif parts[1] == 'link':
            await link_git(message, secret_context)
        elif parts[1] == 'search':
            try:
                what = parts[2]
                if what == 'user':
                    try:
                        git_user = secret_context.git_client.legacy_search_users(
                            parts[3])[0]
                        embed = discord.Embed(title="search result",
                                              type='rich',
                                              description=parts[3],
                                              color=utils.random_color())
                        embed.set_author(name=git_user.login,
                                         url='https://github.com/' +
                                         git_user.login)
                        embed.set_thumbnail(url=git_user.avatar_url)
                        embed.add_field(name='id',
                                        value=str(git_user.id),
                                        inline=False)
                        if git_user.type is not None:
                            embed.add_field(name='type', value=git_user.type)
                        embed.add_field(name='followers',
                                        value=str(git_user.followers))
                        if git_user.contributions is not None:
                            embed.add_field(name='contributions',
                                            value=str(git_user.contributions))
                        if git_user.bio is not None:
                            embed.add_field(name='bio',
                                            value=git_user.bio,
                                            inline=False)
                        await secret_context.discord_client.send_message(
                            message.channel, embed=embed)
                    except Exception as e:
                        embed = utils.simple_embed('info', 'no user found',
                                                   discord.Color.blue())
                        await secret_context.discord_client.send_message(
                            message.channel, embed=embed)
            except Exception as e:
                # just don't reply
                pass
        elif parts[1] == 'unlink':
            try:
                user.User.objects.get(discord_id=message.author.id).delete()
                embed = utils.simple_embed(
                    'success',
                    'you are now unlinked and your points are back to 0',
                    discord.Color.green())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
            except user.DoesNotExist:
                embed = utils.simple_embed(
                    'info', 'you are not linked with any github id',
                    discord.Color.blue())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)
Esempio n. 19
0
async def on_message(message, secret_context):
    parts = message.content.split(" ")
    try:
        location_code = int(parts[1])
        r = requests.get("https://api.accuweather.com/currentconditions/v1/" +
                         str(location_code) + "?apikey=" + API_KEY +
                         "&details=true&getphotos=true")
        j = json.loads(r.content.decode('utf8'))
        if 'code' in j:
            embed = utils.simple_embed(
                'accuweather', 'location id not found. use '
                '!weather search *city_name to get the city code',
                utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
        else:
            obj = j[0]
            embed = utils.simple_embed(
                'accuweather', 'weather conditions for: **' + parts[1] + '**',
                utils.random_color())
            embed.add_field(name='condition',
                            value=obj['WeatherText'],
                            inline=False)
            embed.add_field(
                name='update time',
                value=datetime.fromtimestamp(
                    obj['EpochTime']).strftime('%Y-%m-%d %H:%M:%S'),
                inline=False)
            ct = obj['Temperature']['Metric']['Value']
            cf = obj['Temperature']['Imperial']['Value']
            ct_r = obj['RealFeelTemperature']['Metric']['Value']
            cf_r = obj['RealFeelTemperature']['Imperial']['Value']

            embed.add_field(name='temperature',
                            value=str(ct) + ' **C** | ' + str(cf) + ' **F**')
            embed.add_field(name='real feel',
                            value=str(ct_r) + ' **C** | ' + str(cf_r) +
                            ' **F**')
            embed.add_field(name='humidity',
                            value=str(obj['RelativeHumidity']) + '%')
            embed.add_field(name='cloud cover',
                            value=str(obj['CloudCover']) + '%')
            embed.add_field(name='wind direction',
                            value=str(obj['Wind']['Direction']['Degrees']) +
                            obj['Wind']['Direction']['English'])
            embed.add_field(
                name='wind speed',
                value=str(obj['Wind']['Speed']['Metric']['Value']) + ' km/h')
            embed.set_thumbnail(url=obj['Photos'][0]['PortraitLink'])
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
    except Exception as e:
        if len(parts) < 1:
            embed = utils.simple_embed(
                'accuweather',
                'use !weather search *city_name to get the city code',
                utils.random_color())
            await secret_context.discord_client.send_message(message.channel,
                                                             embed=embed)
        else:
            if len(parts) > 2 and parts[1] == 'search':
                parts = parts[2:]
                q = str.join(" ", parts)
                r = requests.get(
                    "https://api.accuweather.com/locations/v1/cities/autocomplete.json?apikey="
                    + API_KEY + "&language=en&q=" + q)
                j = json.loads(r.content.decode('utf8'))
                if len(j) == 0:
                    embed = utils.simple_embed(
                        'accuweather', 'no city found for **' + q + '**',
                        utils.random_color())
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
                else:
                    embed = utils.simple_embed('accuweather',
                                               'results for **' + q + '**',
                                               utils.random_color())
                    for city in j:
                        embed.add_field(name=city['LocalizedName'],
                                        value=city['Key'],
                                        inline=True)
                    await secret_context.discord_client.send_message(
                        message.channel, embed=embed)
            else:
                embed = utils.simple_embed(
                    'accuweather',
                    'use !weather search *city_name to get the city code',
                    utils.random_color())
                await secret_context.discord_client.send_message(
                    message.channel, embed=embed)