Example #1
0
    async def emojiclock(self, ctx: commands.Context,
                         emoji: Optional[AbsurdEmojiConverter], *,
                         location: str) -> None:
        """Get the time at location (required) in emojis!"""

        emoji = str(emoji or '<:bedoclock:567167125807038464>')  # type: ignore

        # then check for these not-actually-emojis
        not_real_emojis = ['©', '®', '™']
        if emoji in not_real_emojis:
            await ctx.send("*Not a real emoji. (It's complicated.)*")
            return

        # send to helper function
        try:
            emoji_time_string = texttools.emojitime(emoji, location)
        except AttributeError:
            await ctx.send('`You must specify a location for local time!`')
            return

        # split long string
        lines = c.crimsplit(emoji_time_string, '\u2005', limit=1899)
        lines[-1] = lines[-1] + ' \u200B                      \u200B'
        for line in lines:
            await ctx.send(line)
Example #2
0
    async def iss(self, ctx: commands.Context, *, location: str) -> None:
        """
        Find out when the International Space Station will be visible to the naked eye from the location you search!
        Search any location (city, postal code, address, etc).
        The output is data from heavens-above.com that will tell you where in the sky to look and when (in local time).

        · Start: This is where the ISS becomes visible.
          It will take a minute or so longer for it to become visible
          because of the atomosphere and objects (such as trees) on the horizon.
        · Highest: This is its highest point in the pass. Note the elevation in parenthesis.
          For reference, 0° is the horizon and 90° is directly overhead.
        · End: This is where the ISS will pass out of view.
          In late evening passes, this happens well above the horizon.
          You just watched the ISS pass into the Earth's shadow!
        · Brightness: The magnitude is how bright the ISS is expected to be at your location.
          The lower the number, the brighter the ISS will appear. For example, -3.0 is brighter than 1.0!

        (Note: This command works in DM if you want to keep your location private.)
        """

        location = location.upper()
        lat, lon, passes, url = await astronomy.get_iss_loc(location, 'ha')
        string_list = c.crimsplit(passes, '\n', limit=1600)
        for i in range(len(string_list)):
            header_string = 'Visible ISS passes (local time) for {} ({}°, {}°):\n'.format(
                location, lat, lon)
            header_string += 'Source: <{}>\n'.format(url)
            await ctx.send((header_string if i == 0 else '') +
                           '```{}```'.format(string_list[i]))
Example #3
0
    async def e(self, ctx: commands.Context, *, message: str) -> None:
        """Convert message to emojis. Character limit ~450."""

        message = texttools.block(message)
        lines = c.crimsplit(message, ' ', limit=1900)

        if len(lines) > 5:
            raise commands.CommandInvokeError('Too many lines.')

        for line in lines:
            await ctx.send(line)
Example #4
0
    async def scrape(self,
                     ctx: commands.Context,
                     place: str = 'here',
                     join: str = 'space',
                     n: int = 10000) -> None:
        """Scrape messages from channel. >scrape [here/dm/channel_id] [space/newline]."""

        if ctx.message.author.id not in ADMIN_USER_IDS | SCRAPER_USER_IDS:
            return

        file = c.clib_path_join('text', 'scrape.txt')
        if os.path.exists(file):
            os.remove(file)

        channel = ctx.message.channel
        await ctx.message.delete()

        # grab message contents (which are strings):
        async for msg in channel.history(limit=n):
            if not msg.pinned:
                m.scraper(msg.content)

        text = []
        for line in reversed(list(open(file, encoding='utf8',
                                       errors='ignore'))):
            text.append(line.rstrip())

        # haiku only
        for i in range(len(text)):
            if (i + 1) % 3 == 0:
                text[i] = text[i] + '\n\u200A'

        if join == 'space':
            joiner = ' '
        elif join == 'newline':
            joiner = '\n'
        else:
            raise commands.BadArgument('Join type is invalid.')

        msgs = c.crimsplit(joiner.join(text), '\u200A', 1950)
        try:
            if place == 'dm':
                dest = ctx.message.author
            elif place == 'here':
                dest = ctx.message.channel
            else:
                dest = self.bot.get_channel(place)
        except AttributeError:
            raise commands.BadArgument('Destination is invalid.')

        for msg in msgs:
            await dest.send(msg)
Example #5
0
    async def servers(self, ctx: commands.Context) -> None:
        """List crimsoBOT's servers."""

        guilds = self.bot.guilds

        server_string = (f'**Connected on {len(guilds)} servers:**\n' +
                         '\n'.join(f'`{guild.id}` · {guild.name}'
                                   for guild in guilds))

        msg_list = c.crimsplit(server_string, '\n', 1950)

        for msg in msg_list:
            await ctx.send(msg)
Example #6
0
    async def banlist(self, ctx: commands.Context) -> None:
        """List of banned users."""

        banned_users = []
        for user_id in self.bot.banned_user_ids:
            discord_user = await self.bot.fetch_user(user_id)
            banned_users.append('· {u.name}#{u.discriminator}'.format(u=discord_user))

        if not banned_users:
            banned_users.append('No users are banned... yet')

        msg_string = '\n'.join(banned_users)
        msg_list = c.crimsplit(msg_string, '\n', limit=1990)
        for msg in msg_list:
            await ctx.send('```{}```'.format(msg))
Example #7
0
    async def iss(self, ctx: commands.Context, *, location: str) -> None:
        """
        Find out when the International Space Station will be visible to the naked eye from the location you search!
        Search any location (city, postal code, address, etc).
        The output is data from heavens-above.com that will tell you where in the sky to look and when (in local time).

        · Start: This is where the ISS becomes visible.
          It will take a minute or so longer for it to become visible
          because of the atomosphere and objects (such as trees) on the horizon.
        · Highest: This is its highest point in the pass. Note the elevation in parenthesis.
          For reference, 0° is the horizon and 90° is directly overhead.
        · End: This is where the ISS will pass out of view.
          In late evening passes, this happens well above the horizon.
          You just watched the ISS pass into the Earth's shadow!
        · Brightness: The magnitude is how bright the ISS is expected to be at your location.
          The lower the number, the brighter the ISS will appear. For example, -3.0 is brighter than 1.0!

        (Note: This command works in DM if you want to keep your location private.)
        """

        location = location.upper()
        lat, lon, url, passes = await astronomy.get_iss_loc(location)
        if not url:
            raise LocationNotFound(location)

        header_string = (
            f'Visible ISS passes (local time) for {location} ({lat}°, {lon}°):\n'
            f'Source: <{url}>\n')

        formatted_passes = astronomy.format_passes(passes)

        string_list = c.crimsplit(formatted_passes, '\n', limit=1600)
        for i, string in enumerate(string_list):
            # if i is falsey it must be 0, which means we can send without the header string
            await ctx.send(
                f'```{string}```' if i else f'{header_string}```{string}```')