Bla, removed fmt() and bla bla

This commit is contained in:
mrhanky 2017-05-29 18:44:26 +02:00
parent b0dafcfef9
commit 8755e58c4e
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
10 changed files with 62 additions and 70 deletions

View File

@ -7,7 +7,6 @@ from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
from . import Plugin from . import Plugin
from ..utils import fmt
@irc3.plugin @irc3.plugin
@ -22,8 +21,8 @@ class Bitcoin(Plugin):
""" """
data = requests.get('https://www.bitstamp.net/api/ticker').json() data = requests.get('https://www.bitstamp.net/api/ticker').json()
values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']} values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']}
return fmt('{bold}[BitStamp]{reset} ' return '\x02[BitStamp]\x0F ' \
'Current: {bold}{color}{orange}${last:,.2f}{reset} - ' 'Current: \x02\x037${last:,.2f}\x0F - ' \
'High: {bold}{color}{green}${high:,.2f}{reset} - ' 'High: \x02\x033${high:,.2f}\x0F - ' \
'Low: {bold}{color}{maroon}${low:,.2f}{reset} - ' 'Low: \x02\x035${low:,.2f}\x0F - ' \
'Volume: {bold}฿{volume:,.2f}', **values) 'Volume: \x02฿{volume:,.2f}'.format(**values)

View File

@ -7,7 +7,6 @@ from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
from . import Plugin from . import Plugin
from ..utils import fmt
@irc3.plugin @irc3.plugin
@ -27,10 +26,11 @@ class CTCP(Plugin):
reply = 'Error: {reply}'.format(reply=ctcp['reply']) reply = 'Error: {reply}'.format(reply=ctcp['reply'])
else: else:
reply = ctcp['reply'] reply = ctcp['reply']
return fmt('{bold}[{ctcp}]{reset} {nick}: {reply}', return '\x02[{ctcp}]\x0F {nick}: {reply}'.format(
ctcp=name, ctcp=name,
nick=nick, nick=nick,
reply=reply) reply=reply,
)
@command @command
async def ping(self, mask: IrcString, channel: IrcString, async def ping(self, mask: IrcString, channel: IrcString,
@ -54,7 +54,7 @@ class CTCP(Plugin):
else: else:
unit = 's' unit = 's'
reply = '{delta:.3f} {unit}'.format(unit=unit, delta=delta) 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 @command
async def finger(self, mask: IrcString, channel: IrcString, async def finger(self, mask: IrcString, channel: IrcString,

View File

@ -5,7 +5,6 @@ from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
from . import Plugin from . import Plugin
from ..utils import fmt
class Kernel(Plugin): class Kernel(Plugin):
@ -22,6 +21,6 @@ class Kernel(Plugin):
for e in feed['entries']: for e in feed['entries']:
version, branch = e['title'].split(': ') version, branch = e['title'].split(': ')
if '(EOL)' in e['description']: if '(EOL)' in e['description']:
branch = '%s, {italic}EOL{reset}' % branch branch = '%s, \x1DEOL\x0F' % branch
releases.append('{bold}%s{reset} (%s)' % (version, branch)) releases.append('\x02%s\x0F (%s)' % (version, branch))
return fmt('[Kernel] {releases}'.format(releases=', '.join(releases))) return '[Kernel] {releases}'.format(releases=', '.join(releases))

View File

@ -31,7 +31,7 @@ class Seen(DatabasePlugin):
nick=seen['nick'], nick=seen['nick'],
# TODO: relate string delta # TODO: relate string delta
delta=datetime.now() - seen['last_seen'], 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<mask>\S+) PRIVMSG (?P<channel>\S+) :(?P<msg>.*)') @irc3.event(r'(?i)^:(?P<mask>\S+) PRIVMSG (?P<channel>\S+) :(?P<msg>.*)')

View File

@ -8,7 +8,7 @@ from irc3.utils import IrcString
import irc3 import irc3
from . import DatabasePlugin from . import DatabasePlugin
from ..utils import fmt, time_delta from ..utils import time_delta
@irc3.plugin @irc3.plugin
@ -55,8 +55,11 @@ class Timer(DatabasePlugin):
seconds = delta.total_seconds() seconds = delta.total_seconds()
if seconds > 0: if seconds > 0:
await asyncio.sleep(seconds) await asyncio.sleep(seconds)
text = fmt('{bold}[Timer]{reset} {nick}: {message} ({delay})', text = '\x02[Timer]\x0F {nick}: {message} ({delay})'.format(
message=message, delay=delay, nick=mask.nick) message=message,
delay=delay,
nick=mask.nick,
)
self.bot.privmsg(channel, text) self.bot.privmsg(channel, text)
self.cur.execute('delete from timers where id = ?', [row_id]) self.cur.execute('delete from timers where id = ?', [row_id])
self.con.commit() self.con.commit()

View File

@ -7,10 +7,8 @@ from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
from . import Plugin from . import Plugin
from ..utils import fmt
RAINBOW = ('maroon', 'red', 'orange', 'yellow', 'ltgreen', 'green', 'teal', RAINBOW = (5, 3, 7, 8, 9, 3, 10, 12, 2, 6, 13)
'ltblue', 'blue', 'purple', 'pink')
RAINBOW_LEN = len(RAINBOW) RAINBOW_LEN = len(RAINBOW)
GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring
@ -41,7 +39,7 @@ class Useless(Plugin):
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :\[(?P<data>.*)\]$') @irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :\[(?P<data>.*)\]$')
def intensifies(self, channel: str, data: str): def intensifies(self, channel: str, data: str):
self.bot.privmsg(channel, fmt('{bold}[{data} INTENSIFIES]', self.bot.privmsg(channel, '\x02[{data} INTENSIFIES]'.format(
data=data.upper())) data=data.upper()))
@command @command
@ -71,8 +69,9 @@ class Useless(Plugin):
%%jn <question> %%jn <question>
%%jn %%jn
""" """
choice = random.choice(['{green}Ja', '{maroon}Nein']) choice = random.choice(['3Ja', '5Nein'])
return fmt('{nick}: {bold}{color}%s' % choice, nick=mask.nick) return '{nick}: \x02\x03%s'.format(choice=choice,
nick=mask.nick)
@command @command
def kiss(self, mask: IrcString, channel: IrcString, args: DocOptDict): def kiss(self, mask: IrcString, channel: IrcString, args: DocOptDict):
@ -80,8 +79,8 @@ class Useless(Plugin):
%%kiss <nick> %%kiss <nick>
""" """
return fmt('(づ。◕‿‿◕。)づ{color}{red}。。・゜゜・。。・゜❤{reset} {nick} ' return '(づ。◕‿‿◕。)\x033。。・゜゜・。。・゜❤\x0F {nick} \x033❤'.format(
'{color}{red}', nick=args['<nick>']) nick=args['<nick>'])
@command @command
def hug(self, mask: IrcString, channel: IrcString, def hug(self, mask: IrcString, channel: IrcString,
@ -90,8 +89,7 @@ class Useless(Plugin):
%%hug <nick> %%hug <nick>
""" """
return fmt('{color}{red}♥♡❤♡♥{reset} {nick} {color}{red}♥♡❤♡♥', return '\x033♥♡❤♡♥\x0F {nick} \x033♥♡❤♡♥'.format(nick=args['<nick>'])
nick=args['<nick>'])
@command @command
def hack(self, mask: IrcString, channel: IrcString, args: DocOptDict): def hack(self, mask: IrcString, channel: IrcString, args: DocOptDict):
@ -100,7 +98,7 @@ class Useless(Plugin):
%%hack [<nick>] %%hack [<nick>]
""" """
nick = args.get('<nick>') or '' nick = args.get('<nick>') or ''
return 'hacking{}...'.format(' %s' % nick if nick else '') return 'hacking{nick}...'.format(nick=' %s' % nick if nick else '')
@command @command
def gay(self, mask: IrcString, channel: IrcString, args: DocOptDict): def gay(self, mask: IrcString, channel: IrcString, args: DocOptDict):
@ -120,10 +118,10 @@ class Useless(Plugin):
word = [] word = []
for i, char in enumerate(' '.join(args.get('<word>'))): for i, char in enumerate(' '.join(args.get('<word>'))):
if char != ' ': if char != ' ':
char = '{color}{%s}%s' % (RAINBOW[last % RAINBOW_LEN], char) char = self._rainbow(last, char)
last += 1 last += 1
word.append(char) word.append(char)
return fmt(''.join(word)) return ''.join(word)
@command @command
def wrainbow(self, mask: IrcString, channel: IrcString, args: DocOptDict): def wrainbow(self, mask: IrcString, channel: IrcString, args: DocOptDict):
@ -131,5 +129,10 @@ class Useless(Plugin):
%%wrainbow <words>... %%wrainbow <words>...
""" """
return fmt(' '.join(['{color}{%s}%s' % (RAINBOW[i % RAINBOW_LEN], word) return ' '.join([self._rainbow(i, word) for i, word
for i, word in enumerate(args['<words>'])])) in enumerate(args['<words>'])])
@staticmethod
def _rainbow(i, char):
return '\x03{color}{char}'.format(color=RAINBOW[i % RAINBOW_LEN],
char=char)

View File

@ -10,7 +10,7 @@ from irc3.plugins.command import command
from irc3.utils import IrcString from irc3.utils import IrcString
from . import Plugin from . import Plugin
from ..utils import fmt, date_from_iso from ..utils import date_from_iso
# TODO: write better code lol # TODO: write better code lol
@ -46,22 +46,22 @@ class YouTube(Plugin):
except ZeroDivisionError: except ZeroDivisionError:
score = 0 score = 0
stats = fmt(' -{color}{green} {likes:,}{reset} /{color}{maroon} ' stats = ' -\x033 {likes:,}\x0F /\x035 ' \
'{dislikes:,}{reset} ({score:,.1f}%) ' '{dislikes:,}\x0F ({score:,.1f}%) ' \
'- {views:,} views', '- {views:,} views'.format(likes=likes,
likes=likes,
dislikes=dislikes, dislikes=dislikes,
score=score, score=score,
views=views) views=views)
except KeyError: except KeyError:
stats = '' stats = ''
return fmt('{title}{length}{stats} - {channel} on {date}', return '{title}{length}{stats} - {channel} on {date}'.format(
title=item['snippet']['title'], title=item['snippet']['title'],
channel=item['snippet']['channelTitle'], channel=item['snippet']['channelTitle'],
length=length, length=length,
date=date.strftime('%Y.%m.%d'), date=date.strftime('%Y.%m.%d'),
stats=stats) stats=stats,
)
@event(r'(?i)^:.* PRIVMSG (?P<target>.*) :.*(?:youtube.*?(?:v=|/v/)' @event(r'(?i)^:.* PRIVMSG (?P<target>.*) :.*(?:youtube.*?(?:v=|/v/)'
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*') r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')

View File

@ -2,7 +2,6 @@
from pprint import pprint as pp from pprint import pprint as pp
from .date import date_from_iso, time_delta, time_since from .date import date_from_iso, time_delta, time_since
from .formatting import fmt, FORMATTING
from .misc import parse_int from .misc import parse_int
__all__ = ( __all__ = (
@ -12,9 +11,6 @@ __all__ = (
'date_from_iso', 'date_from_iso',
'time_delta', 'time_delta',
'time_since', 'time_since',
# formatting
'fmt',
'FORMATTING',
# misc # misc
'parse_int' 'parse_int'
) )

View File

@ -28,11 +28,4 @@ FORMATTING = {
'swap': '\x16', # swap bg and fg colors ("reverse video") 'swap': '\x16', # swap bg and fg colors ("reverse video")
'reset': '\x0F', # reset all formatting 'reset': '\x0F', # reset all formatting
} }
FORMATTING.update(COLORS)
# @formatter:on # @formatter:on
def fmt(__text: str, **kwargs) -> str:
"""Formats a str with `kwargs` and `FORMATTING`."""
return __text.format(**kwargs, **FORMATTING)

View File

@ -1,14 +1,14 @@
create table if not exists quotes ( create table if not exists quotes (
id integer primary key autoincrement, id integer primary key autoincrement,
nick text not null, nick text not null collate nocase,
item text not null, item text not null collate nocase,
unique (nick, item collate nocase) unique (nick, item)
); );
create table if not exists mcmaniacs ( create table if not exists mcmaniacs (
id integer primary key autoincrement, id integer primary key autoincrement,
item text not null, item text not null collate nocase,
unique (item collate nocase) on conflict replace unique (item) on conflict replace
); );
create table if not exists timers ( create table if not exists timers (
@ -30,12 +30,11 @@ create table if not exists tells (
unique (to_user, message) unique (to_user, message)
); );
create table if not exists seens ( create table if not exists seens (
id integer primary key autoincrement, id integer primary key autoincrement,
nick text not null, nick text not null collate nocase,
channel text not null, channel text not null collate nocase,
message text not null, message text not null,
last_seen timestamp not null, last_seen timestamp not null,
unique (nick collate nocase) on conflict replace unique (nick) on conflict replace
); );