Esempio n. 1
0
async def countdown_timer(ircbot, duration_in_seconds, srl_channel, beginmessage=False):
    loop = asyncio.get_running_loop()

    reminders = [1800, 1500, 1200, 900, 600, 300,
                 120, 60, 30, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    start_time = loop.time()
    end_time = loop.time() + duration_in_seconds
    while True:
        # print(datetime.datetime.now())
        timeleft = math.ceil(start_time - loop.time() + duration_in_seconds)
        # print(timeleft)
        if timeleft in reminders:
            minutes = math.floor(timeleft/60)
            seconds = math.ceil(timeleft % 60)
            if minutes == 0 and seconds > 10:
                msg = f'{seconds} second(s) remain!'
            elif minutes == 0 and seconds <= 10:
                msg = ircmessage.style(
                    f"{seconds} second(s) remain!", fg='green', bold=True)
            else:
                msg = f'{minutes} minute(s), {seconds} seconds remain!'
            await ircbot.message(srl_channel, msg)
            reminders.remove(timeleft)
        if loop.time() >= end_time:
            if beginmessage:
                await ircbot.message(srl_channel, ircmessage.style('Log study has finished.  Begin racing!', fg='red', bold=True))
            break
        await asyncio.sleep(.5)
Esempio n. 2
0
async def countdown_timer(duration_in_seconds,
                          srl_channel,
                          loop,
                          ircbot,
                          beginmessage=False):
    reminders = [900, 600, 300, 120, 60, 30, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    start_time = loop.time()
    end_time = loop.time() + duration_in_seconds
    while True:
        # print(datetime.datetime.now())
        timeleft = math.ceil(start_time - loop.time() + duration_in_seconds)
        # print(timeleft)
        if timeleft in reminders:
            minutes = math.floor(timeleft / 60)
            seconds = math.ceil(timeleft % 60)
            if minutes == 0 and seconds > 10:
                msg = '{seconds} second(s) remain!'.format(seconds=seconds)
            elif minutes == 0 and seconds <= 10:
                msg = '{seconds} second(s) remain!'.format(seconds=seconds, )
                msg = ircmessage.style(msg, fg='green', bold=True)
            else:
                msg = '{minutes} minute(s), {seconds} seconds remain!'.format(
                    minutes=minutes, seconds=seconds)
            ircbot.send('PRIVMSG', target=srl_channel, message=msg)
            reminders.remove(timeleft)
        if loop.time() >= end_time:
            if beginmessage:
                ircbot.send('PRIVMSG',
                            target=srl_channel,
                            message=ircmessage.style(
                                'Log study has finished.  Begin racing!',
                                fg='red',
                                bold=True))
            break
        await asyncio.sleep(.5)
Esempio n. 3
0
        def _define(args, response):
            """
            @type   args:       argparse.Namespace
            @type   response:   firefly.containers.Response
            """
            # Fetch our definitions
            self._log.info('Fetching up to {max} definitions for the word {word}'
                           .format(max=args.results, word=args.word))
            definitions = self._get_definitions(args.word, args.results)

            if not definitions:
                response.add_message(
                    "Sorry, I couldn't find any definitions for {word}.".format(word=style(args.word, bold=True))
                )

            # Format our definitions
            formatted_definitions = []
            for index, definition in enumerate(definitions):
                if not formatted_definitions:
                    formatted_definitions.append("{word} ({pos}) {key} {definition}"
                                                 .format(word=style(args.word, bold=True),
                                                         pos=style(definition[1], italics=True),
                                                         key=style('1:', bold=True), definition=definition[2]))
                else:
                    formatted_definitions.append("{key} {definition}"
                                                 .format(key=style(str(index + 1), bold=True),
                                                         definition=definition[2]))

            self._log.debug('Returning %d definitions', len(formatted_definitions))
            response.add_message(' '.join(formatted_definitions))
Esempio n. 4
0
    def test_fg_and_bg_with_attributes(self):
        message = ircmessage.style('Hello, world!', fg='yellow', bg='blue', bold=True, underline=True)
        self.assertEqual(message, '\x0308,02\x02\x1fHello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.yellow, bg=ircmessage.colors.blue,
                                   bold=True, underline=True)
        self.assertEqual(message, '\x0308,02\x02\x1fHello, world!\x0F')
Esempio n. 5
0
    def test_fg_royal(self):
        message = ircmessage.style('Hello, world!', fg='royal')
        self.assertEqual(message, '\x0312Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.royal)
        self.assertEqual(message, '\x0312Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.light_blue)
        self.assertEqual(message, '\x0312Hello, world!\x0F')
Esempio n. 6
0
    def test_fg_aqua(self):
        message = ircmessage.style('Hello, world!', fg='aqua')
        self.assertEqual(message, '\x0311Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.aqua)
        self.assertEqual(message, '\x0311Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.light_cyan)
        self.assertEqual(message, '\x0311Hello, world!\x0F')
Esempio n. 7
0
    def test_fg_teal(self):
        message = ircmessage.style('Hello, world!', fg='teal')
        self.assertEqual(message, '\x0310Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.teal)
        self.assertEqual(message, '\x0310Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.cyan)
        self.assertEqual(message, '\x0310Hello, world!\x0F')
Esempio n. 8
0
    def test_fg_lime(self):
        message = ircmessage.style('Hello, world!', fg='lime')
        self.assertEqual(message, '\x0309Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.lime)
        self.assertEqual(message, '\x0309Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.light_green)
        self.assertEqual(message, '\x0309Hello, world!\x0F')
Esempio n. 9
0
    def test_fg_silver(self):
        message = ircmessage.style('Hello, world!', fg='silver')
        self.assertEqual(message, '\x0315Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.silver)
        self.assertEqual(message, '\x0315Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.light_grey)
        self.assertEqual(message, '\x0315Hello, world!\x0F')
Esempio n. 10
0
        def _poke(args, response):
            """
            @type   args:       argparse.Namespace
            @type   response:    firefly.containers.Response
            """
            if args.times:
                for c in range(0, args.times):
                    response.add_message(style('poke', args.color))

            return response
Esempio n. 11
0
        def _search(args, response):
            """
            @type   args:       argparse.Namespace
            @type   response:   firefly.containers.Response
            """
            try:
                query = ' '.join(args.query)
                results = google_search(query, args.results)
            except PoogleNoResultsError:
                message = "Sorry, I couldn't find anything for {q}".format(q=style(query, bold=True))
                response.add_message(message)
                return

            formatted_results = []
            for result in results:
                formatted_results.append(
                    self.template.format(title=style(result.title, bold=True), url=result.url.as_string())
                )

            response.add_message(
                self.separator.join(formatted_results)
            )
Esempio n. 12
0
        def _lucky(args, response):
            """
            @type   args:       argparse.Namespace
            @type   response:   firefly.containers.Response
            """
            try:
                query = ' '.join(args.query)
                results = google_search(query, 1)
            except PoogleNoResultsError:
                message = "Sorry, I couldn't find anything for {q}".format(q=style(query, bold=True))
                response.add_message(message)
                return

            response.add_message(results[0].url.as_string())
Esempio n. 13
0
    def matches(self, mask, target, args):
        """List interesting Red Eclipse matches

            %%matches
        """

        if not self.redflare_url:
            yield "Redflare URL not configured"
            return

        rfc = RedflareClient(self.redflare_url)
        servers = rfc.servers()

        # i: Server
        non_empty_legacy_servers = [s for s in servers if s.players_count > 0 and not s.version.startswith("2.")]

        if not non_empty_legacy_servers:
            yield "No legacy matches running at the moment."
            return

        for server in sorted(non_empty_legacy_servers, key=lambda s: s.players_count, reverse=True):
            players = [p.name for p in server.players]

            # the colors we use to format player names
            colors = ["red", "pink", "green", "teal", "orange", None]
            # make things a bit more interesting by randomizing the order
            random.shuffle(colors)
            # however, once the order is defined, just apply those colors in the ever same order to nicks in the list
            # it'd be nice to assign some sort of "persistent" colors derived from the nicks
            colors = itertools.cycle(colors)

            # this is the "freem exception"
            # freem doesnt like to be pinged on IRC whenever !matches is called while they are playing
            # the easiest way to fix this is to just change the name in the listing
            # ofc this only works until freem decides to use another nickname
            players = ["_freem_" if p == "freem" else p for p in players]

            message = "%s on %s (%s): %s %s on %s" % (
                ircmessage.style(str(server.players_count), fg="red"),
                ircmessage.style("%s" % server.description, fg="orange"),
                ", ".join((ircmessage.style(p, fg=next(colors)) for p in players)),
                ircmessage.style("-".join(server.mutators), fg="teal"),
                ircmessage.style(server.game_mode, fg="green"),
                ircmessage.style(server.map_name, fg="pink"),
            )

            print(repr(message))

            yield message
Esempio n. 14
0
        def _last(args, response):
            """
            @type   response:   firefly.containers.Response
            """
            reply = self._last_logging(args, response) if self.logger else self._last_fallback(args, response)
            if not reply:
                response.add_message(random.choice(self.NOT_SEEN_RESPONSES).format(name=args.nick.title()))
                return

            date, nick, message = reply
            bits = []

            # Get the formatted date string
            date_string = date.humanize() if args.relative else date.format('MMMM DD, YYYY - HH:mm A ZZ')
            bits.append(style(date_string, bold=args.message))

            if args.message:
                bits.append(': <{nick}> {msg}'.format(nick=nick, msg=message))

            response.add_message(''.join(bits))
Esempio n. 15
0
    def test_fg_purple(self):
        message = ircmessage.style('Hello, world!', fg='purple')
        self.assertEqual(message, '\x0306Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.purple)
        self.assertEqual(message, '\x0306Hello, world!\x0F')
Esempio n. 16
0
    def test_fg_orange(self):
        message = ircmessage.style('Hello, world!', fg='orange')
        self.assertEqual(message, '\x0307Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.orange)
        self.assertEqual(message, '\x0307Hello, world!\x0F')
Esempio n. 17
0
 def test_bold_with_reset(self):
     message = ircmessage.style('Hello, world!', bold=True)
     self.assertEqual(message, '\x02Hello, world!\x0F')
Esempio n. 18
0
    def test_fg_brown(self):
        message = ircmessage.style('Hello, world!', fg='brown')
        self.assertEqual(message, '\x0305Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.brown)
        self.assertEqual(message, '\x0305Hello, world!\x0F')
Esempio n. 19
0
    def test_fg_and_bg_no_reset(self):
        message = ircmessage.style('Hello, world!', fg='yellow', bg='blue', reset=False)
        self.assertEqual(message, '\x0308,02Hello, world!')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.yellow, bg=ircmessage.colors.blue, reset=False)
        self.assertEqual(message, '\x0308,02Hello, world!')
Esempio n. 20
0
    def test_fg_red(self):
        message = ircmessage.style('Hello, world!', fg='red')
        self.assertEqual(message, '\x0304Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.red)
        self.assertEqual(message, '\x0304Hello, world!\x0F')
Esempio n. 21
0
    def test_fg_white(self):
        message = ircmessage.style('Hello, world!', fg='white')
        self.assertEqual(message, '\x0300Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.white)
        self.assertEqual(message, '\x0300Hello, world!\x0F')
Esempio n. 22
0
import argparse
import shlex
import sys

import ircmessage

from alttprbot.alttprgen import mystery, preset, spoilers
from alttprbot.database import (config, spoiler_races, srl_races,
                                tournament_results)
from alttprbot.exceptions import SahasrahBotException
from alttprbot.tournament import league
from alttprbot.util.srl import get_race, srl_race_id

ACCESSIBLE_RACE_WARNING = ircmessage.style(
    'WARNING: ', bold=True, fg='red'
) + ircmessage.style(
    'This race is using an accessible ruleset that prohibits most sequence breaking glitches.  Please visit https://link.alttpr.com/accessible for more details!',
    fg='red')


async def handler(target, source, message, client):
    if not message[0] == '$':
        return

    try:
        args = await parse_args(message)
    except argparse.ArgumentError as err:
        if not target == '#speedrunslive':
            await client.message(target, err.message)
        return
Esempio n. 23
0
 def test_underline_without_reset(self):
     message = ircmessage.style('Hello, world!', underline=True, reset=False)
     self.assertEqual(message, '\x1FHello, world!')
Esempio n. 24
0
 def test_complex_attributes_without_reset(self):
     message = ircmessage.style('Hello, world!', bold=True, italics=True, underline=True, reset=False)
     self.assertEqual(message, '\x02\x1d\x1fHello, world!')
Esempio n. 25
0
    def test_fg_pink(self):
        message = ircmessage.style('Hello, world!', fg='pink')
        self.assertEqual(message, '\x0313Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.pink)
        self.assertEqual(message, '\x0313Hello, world!\x0F')
Esempio n. 26
0
def style(text: str, **style_config: Optional[Dict[str, str]]) -> str:
    return ircmessage.style(text, **style_config, reset=True) if (
        style_config and any(style_config.values())) else text
Esempio n. 27
0
 def test_italics_with_reset(self):
     message = ircmessage.style('Hello, world!', italics=True)
     self.assertEqual(message, '\x1DHello, world!\x0F')
Esempio n. 28
0
 def test_bold_without_reset(self):
     message = ircmessage.style('Hello, world!', bold=True, reset=False)
     self.assertEqual(message, '\x02Hello, world!')
Esempio n. 29
0
    def test_fg_blue(self):
        message = ircmessage.style('Hello, world!', fg='blue')
        self.assertEqual(message, '\x0302Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.blue)
        self.assertEqual(message, '\x0302Hello, world!\x0F')
Esempio n. 30
0
    def test_fg_yellow(self):
        message = ircmessage.style('Hello, world!', fg='yellow')
        self.assertEqual(message, '\x0308Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.yellow)
        self.assertEqual(message, '\x0308Hello, world!\x0F')
Esempio n. 31
0
    def test_fg_green(self):
        message = ircmessage.style('Hello, world!', fg='green')
        self.assertEqual(message, '\x0303Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.green)
        self.assertEqual(message, '\x0303Hello, world!\x0F')
Esempio n. 32
0
 def test_underline_with_reset(self):
     message = ircmessage.style('Hello, world!', underline=True)
     self.assertEqual(message, '\x1FHello, world!\x0F')
Esempio n. 33
0
    def test_fg_and_bg(self):
        message = ircmessage.style('Hello, world!', fg='yellow', bg='blue')
        self.assertEqual(message, '\x0308,02Hello, world!\x0F')

        message = ircmessage.style('Hello, world!', fg=ircmessage.colors.yellow, bg=ircmessage.colors.blue)
        self.assertEqual(message, '\x0308,02Hello, world!\x0F')
Esempio n. 34
0
 def test_italics_without_reset(self):
     message = ircmessage.style('Hello, world!', italics=True, reset=False)
     self.assertEqual(message, '\x1DHello, world!')
Esempio n. 35
0
        def _login(args, response):
            """
            @type   response:   firefly.containers.Response
            """
            try:
                self.firefly.auth.attempt(response.request.source, args.email, args.password)
            except AuthAlreadyLoggedInError as e:
                response.add_message('You are already logged in to an account.')
                return
            except AuthError:
                response.add_message('Login failed; An invalid email or password was provided.')
                return

            response.add_message('You have successfully logged in as {user}.'.format(user=style(args.email, bold=True)))