From 8755e58c4e1e7c81d684adb60b79acc7d73ff15d Mon Sep 17 00:00:00 2001 From: mrhanky Date: Mon, 29 May 2017 18:44:26 +0200 Subject: [PATCH] Bla, removed fmt() and bla bla --- nxy/plugins/bitcoin.py | 11 +++++------ nxy/plugins/ctcp.py | 12 ++++++------ nxy/plugins/kernel.py | 7 +++---- nxy/plugins/seen.py | 2 +- nxy/plugins/timer.py | 9 ++++++--- nxy/plugins/useless.py | 35 +++++++++++++++++++---------------- nxy/plugins/youtube.py | 28 ++++++++++++++-------------- nxy/utils/__init__.py | 4 ---- nxy/utils/formatting.py | 7 ------- schema.sql | 17 ++++++++--------- 10 files changed, 62 insertions(+), 70 deletions(-) diff --git a/nxy/plugins/bitcoin.py b/nxy/plugins/bitcoin.py index a8f3358..31c9aad 100644 --- a/nxy/plugins/bitcoin.py +++ b/nxy/plugins/bitcoin.py @@ -7,7 +7,6 @@ from irc3.plugins.command import command from irc3.utils import IrcString from . import Plugin -from ..utils import fmt @irc3.plugin @@ -22,8 +21,8 @@ class Bitcoin(Plugin): """ data = requests.get('https://www.bitstamp.net/api/ticker').json() values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']} - return fmt('{bold}[BitStamp]{reset} ' - 'Current: {bold}{color}{orange}${last:,.2f}{reset} - ' - 'High: {bold}{color}{green}${high:,.2f}{reset} - ' - 'Low: {bold}{color}{maroon}${low:,.2f}{reset} - ' - 'Volume: {bold}฿{volume:,.2f}', **values) + return '\x02[BitStamp]\x0F ' \ + 'Current: \x02\x037${last:,.2f}\x0F - ' \ + 'High: \x02\x033${high:,.2f}\x0F - ' \ + 'Low: \x02\x035${low:,.2f}\x0F - ' \ + 'Volume: \x02฿{volume:,.2f}'.format(**values) diff --git a/nxy/plugins/ctcp.py b/nxy/plugins/ctcp.py index ae34280..99858b7 100644 --- a/nxy/plugins/ctcp.py +++ b/nxy/plugins/ctcp.py @@ -7,7 +7,6 @@ from irc3.plugins.command import command from irc3.utils import IrcString from . import Plugin -from ..utils import fmt @irc3.plugin @@ -27,10 +26,11 @@ class CTCP(Plugin): reply = 'Error: {reply}'.format(reply=ctcp['reply']) else: reply = ctcp['reply'] - return fmt('{bold}[{ctcp}]{reset} {nick}: {reply}', - ctcp=name, - nick=nick, - reply=reply) + return '\x02[{ctcp}]\x0F {nick}: {reply}'.format( + ctcp=name, + nick=nick, + reply=reply, + ) @command async def ping(self, mask: IrcString, channel: IrcString, @@ -54,7 +54,7 @@ class CTCP(Plugin): else: unit = 's' reply = '{delta:.3f} {unit}'.format(unit=unit, delta=delta) - return fmt('{bold}[PING]{reset} {nick}: {text}', nick=nick, text=reply) + return '\x02[PING]\x0F {nick}: {text}'.format(nick=nick, text=reply) @command async def finger(self, mask: IrcString, channel: IrcString, diff --git a/nxy/plugins/kernel.py b/nxy/plugins/kernel.py index cab4627..62bbdaf 100644 --- a/nxy/plugins/kernel.py +++ b/nxy/plugins/kernel.py @@ -5,7 +5,6 @@ from irc3.plugins.command import command from irc3.utils import IrcString from . import Plugin -from ..utils import fmt class Kernel(Plugin): @@ -22,6 +21,6 @@ class Kernel(Plugin): for e in feed['entries']: version, branch = e['title'].split(': ') if '(EOL)' in e['description']: - branch = '%s, {italic}EOL{reset}' % branch - releases.append('{bold}%s{reset} (%s)' % (version, branch)) - return fmt('[Kernel] {releases}'.format(releases=', '.join(releases))) + branch = '%s, \x1DEOL\x0F' % branch + releases.append('\x02%s\x0F (%s)' % (version, branch)) + return '[Kernel] {releases}'.format(releases=', '.join(releases)) diff --git a/nxy/plugins/seen.py b/nxy/plugins/seen.py index db8c3a9..59ec771 100644 --- a/nxy/plugins/seen.py +++ b/nxy/plugins/seen.py @@ -31,7 +31,7 @@ class Seen(DatabasePlugin): nick=seen['nick'], # TODO: relate string delta delta=datetime.now() - seen['last_seen'], - message=re.sub(r'\x01ACTION (.*)\x01', r'\1', seen['message']), + message=re.sub(r'\x01ACTION (.*)\x01', r'/me \1', seen['message']), ) @irc3.event(r'(?i)^:(?P\S+) PRIVMSG (?P\S+) :(?P.*)') diff --git a/nxy/plugins/timer.py b/nxy/plugins/timer.py index 34a537a..e6fa405 100644 --- a/nxy/plugins/timer.py +++ b/nxy/plugins/timer.py @@ -8,7 +8,7 @@ from irc3.utils import IrcString import irc3 from . import DatabasePlugin -from ..utils import fmt, time_delta +from ..utils import time_delta @irc3.plugin @@ -55,8 +55,11 @@ class Timer(DatabasePlugin): seconds = delta.total_seconds() if seconds > 0: await asyncio.sleep(seconds) - text = fmt('{bold}[Timer]{reset} {nick}: {message} ({delay})', - message=message, delay=delay, nick=mask.nick) + text = '\x02[Timer]\x0F {nick}: {message} ({delay})'.format( + message=message, + delay=delay, + nick=mask.nick, + ) self.bot.privmsg(channel, text) self.cur.execute('delete from timers where id = ?', [row_id]) self.con.commit() diff --git a/nxy/plugins/useless.py b/nxy/plugins/useless.py index acc2ac3..d7ee0f7 100644 --- a/nxy/plugins/useless.py +++ b/nxy/plugins/useless.py @@ -7,10 +7,8 @@ from irc3.plugins.command import command from irc3.utils import IrcString from . import Plugin -from ..utils import fmt -RAINBOW = ('maroon', 'red', 'orange', 'yellow', 'ltgreen', 'green', 'teal', - 'ltblue', 'blue', 'purple', 'pink') +RAINBOW = (5, 3, 7, 8, 9, 3, 10, 12, 2, 6, 13) RAINBOW_LEN = len(RAINBOW) GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring @@ -41,8 +39,8 @@ class Useless(Plugin): @irc3.event(r'(?i)^:\S+ PRIVMSG (?P\S+) :\[(?P.*)\]$') def intensifies(self, channel: str, data: str): - self.bot.privmsg(channel, fmt('{bold}[{data} INTENSIFIES]', - data=data.upper())) + self.bot.privmsg(channel, '\x02[{data} INTENSIFIES]'.format( + data=data.upper())) @command def storyofpomfface(self, mask: IrcString, channel: IrcString, @@ -71,8 +69,9 @@ class Useless(Plugin): %%jn %%jn """ - choice = random.choice(['{green}Ja', '{maroon}Nein']) - return fmt('{nick}: {bold}{color}%s' % choice, nick=mask.nick) + choice = random.choice(['3Ja', '5Nein']) + return '{nick}: \x02\x03%s'.format(choice=choice, + nick=mask.nick) @command def kiss(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -80,8 +79,8 @@ class Useless(Plugin): %%kiss """ - return fmt('(づ。◕‿‿◕。)づ{color}{red}。。・゜゜・。。・゜❤{reset} {nick} ' - '{color}{red}❤', nick=args['']) + return '(づ。◕‿‿◕。)\x033。。・゜゜・。。・゜❤\x0F {nick} \x033❤'.format( + nick=args['']) @command def hug(self, mask: IrcString, channel: IrcString, @@ -90,8 +89,7 @@ class Useless(Plugin): %%hug """ - return fmt('{color}{red}♥♡❤♡♥{reset} {nick} {color}{red}♥♡❤♡♥', - nick=args['']) + return '\x033♥♡❤♡♥\x0F {nick} \x033♥♡❤♡♥'.format(nick=args['']) @command def hack(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -100,7 +98,7 @@ class Useless(Plugin): %%hack [] """ nick = args.get('') or '' - return 'hacking{}...'.format(' %s' % nick if nick else '') + return 'hacking{nick}...'.format(nick=' %s' % nick if nick else '') @command def gay(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -120,10 +118,10 @@ class Useless(Plugin): word = [] for i, char in enumerate(' '.join(args.get(''))): if char != ' ': - char = '{color}{%s}%s' % (RAINBOW[last % RAINBOW_LEN], char) + char = self._rainbow(last, char) last += 1 word.append(char) - return fmt(''.join(word)) + return ''.join(word) @command def wrainbow(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -131,5 +129,10 @@ class Useless(Plugin): %%wrainbow ... """ - return fmt(' '.join(['{color}{%s}%s' % (RAINBOW[i % RAINBOW_LEN], word) - for i, word in enumerate(args[''])])) + return ' '.join([self._rainbow(i, word) for i, word + in enumerate(args[''])]) + + @staticmethod + def _rainbow(i, char): + return '\x03{color}{char}'.format(color=RAINBOW[i % RAINBOW_LEN], + char=char) diff --git a/nxy/plugins/youtube.py b/nxy/plugins/youtube.py index ce20e99..a540574 100644 --- a/nxy/plugins/youtube.py +++ b/nxy/plugins/youtube.py @@ -10,7 +10,7 @@ from irc3.plugins.command import command from irc3.utils import IrcString from . import Plugin -from ..utils import fmt, date_from_iso +from ..utils import date_from_iso # TODO: write better code lol @@ -46,22 +46,22 @@ class YouTube(Plugin): except ZeroDivisionError: score = 0 - stats = fmt(' -{color}{green} {likes:,}{reset} /{color}{maroon} ' - '{dislikes:,}{reset} ({score:,.1f}%) ' - '- {views:,} views', - likes=likes, - dislikes=dislikes, - score=score, - views=views) + stats = ' -\x033 {likes:,}\x0F /\x035 ' \ + '{dislikes:,}\x0F ({score:,.1f}%) ' \ + '- {views:,} views'.format(likes=likes, + dislikes=dislikes, + score=score, + views=views) except KeyError: stats = '' - return fmt('{title}{length}{stats} - {channel} on {date}', - title=item['snippet']['title'], - channel=item['snippet']['channelTitle'], - length=length, - date=date.strftime('%Y.%m.%d'), - stats=stats) + return '{title}{length}{stats} - {channel} on {date}'.format( + title=item['snippet']['title'], + channel=item['snippet']['channelTitle'], + length=length, + date=date.strftime('%Y.%m.%d'), + stats=stats, + ) @event(r'(?i)^:.* PRIVMSG (?P.*) :.*(?:youtube.*?(?:v=|/v/)' r'|youtu\.be/)(?P[-_a-zA-Z0-9]+).*') diff --git a/nxy/utils/__init__.py b/nxy/utils/__init__.py index bea46b5..8f49b70 100644 --- a/nxy/utils/__init__.py +++ b/nxy/utils/__init__.py @@ -2,7 +2,6 @@ from pprint import pprint as pp from .date import date_from_iso, time_delta, time_since -from .formatting import fmt, FORMATTING from .misc import parse_int __all__ = ( @@ -12,9 +11,6 @@ __all__ = ( 'date_from_iso', 'time_delta', 'time_since', - # formatting - 'fmt', - 'FORMATTING', # misc 'parse_int' ) diff --git a/nxy/utils/formatting.py b/nxy/utils/formatting.py index f8340da..d11edd7 100644 --- a/nxy/utils/formatting.py +++ b/nxy/utils/formatting.py @@ -28,11 +28,4 @@ FORMATTING = { 'swap': '\x16', # swap bg and fg colors ("reverse video") 'reset': '\x0F', # reset all formatting } - -FORMATTING.update(COLORS) # @formatter:on - - -def fmt(__text: str, **kwargs) -> str: - """Formats a str with `kwargs` and `FORMATTING`.""" - return __text.format(**kwargs, **FORMATTING) diff --git a/schema.sql b/schema.sql index 5f453c8..320a821 100644 --- a/schema.sql +++ b/schema.sql @@ -1,14 +1,14 @@ create table if not exists quotes ( id integer primary key autoincrement, - nick text not null, - item text not null, - unique (nick, item collate nocase) + nick text not null collate nocase, + item text not null collate nocase, + unique (nick, item) ); create table if not exists mcmaniacs ( id integer primary key autoincrement, - item text not null, - unique (item collate nocase) on conflict replace + item text not null collate nocase, + unique (item) on conflict replace ); create table if not exists timers ( @@ -30,12 +30,11 @@ create table if not exists tells ( unique (to_user, message) ); - create table if not exists seens ( id integer primary key autoincrement, - nick text not null, - channel text not null, + nick text not null collate nocase, + channel text not null collate nocase, message text not null, last_seen timestamp not null, - unique (nick collate nocase) on conflict replace + unique (nick) on conflict replace );