diff --git a/nxy/plugins/coins.py b/nxy/plugins/coins.py index 459e456..55d3b08 100644 --- a/nxy/plugins/coins.py +++ b/nxy/plugins/coins.py @@ -21,10 +21,10 @@ class Coins(Plugin): """ data = requests.get('https://www.bitstamp.net/api/ticker').json() values = {k: float(data[k]) for k in ['last', 'high', 'low', 'volume']} - return '\x02[BitStamp]\x02 ' \ + return '\x02[Bitcoin]\x02 ' \ 'Current: \x02\x037${last:,.2f}\x0F - ' \ 'High: \x02\x033${high:,.2f}\x0F - ' \ - 'Low: \x02\x035${low:,.2f}\x0F - ' \ + 'Low: \x02\x034${low:,.2f}\x0F - ' \ 'Volume: \x02฿{volume:,.2f}\x02'.format(**values) @command diff --git a/nxy/plugins/ctcp.py b/nxy/plugins/ctcp.py index 99858b7..27ea276 100644 --- a/nxy/plugins/ctcp.py +++ b/nxy/plugins/ctcp.py @@ -14,24 +14,28 @@ class CTCP(Plugin): requires = ['irc3.plugins.async', 'irc3.plugins.command'] - TIMEOUT = 10 - - async def ctcp(self, ctcp: str, mask: IrcString, args: DocOptDict): - nick = args.get('') or mask.nick - name = ctcp.upper() - ctcp = await self.bot.ctcp_async(nick, name, timeout=self.TIMEOUT) - if not ctcp or ctcp['timeout']: - reply = 'timeout' - elif not ctcp['success']: - reply = 'Error: {reply}'.format(reply=ctcp['reply']) - else: - reply = ctcp['reply'] - return '\x02[{ctcp}]\x0F {nick}: {reply}'.format( - ctcp=name, + @staticmethod + def _ctcp(name: str, nick: str, reply: str): + return '\x02[{name}]\x02 {nick}: {reply}'.format( + name=name.upper(), nick=nick, reply=reply, ) + async def ctcp(self, name: str, mask: IrcString, args: DocOptDict): + nick = args.get('') or mask.nick + name = name.upper() + data = await self.bot.ctcp_async(nick, name) + + if not data or data['timeout']: + reply = 'timeout' + elif not data['success']: + reply = 'Error: {reply}'.format(reply=data['reply']) + else: + reply = data['reply'] + + return self._ctcp(name, nick, reply) + @command async def ping(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -40,21 +44,22 @@ class CTCP(Plugin): %%ping [] """ nick = args.get('') or mask.nick - ctcp = await self.bot.ctcp_async(nick, 'PING {0}'.format(time.time()), - timeout=self.TIMEOUT) - if not ctcp or ctcp['timeout']: + data = await self.bot.ctcp_async(nick, 'PING {0}'.format(time.time())) + + if not data or data['timeout']: reply = 'timeout' - elif not ctcp['success']: - reply = 'Error: {reply}'.format(reply=ctcp['reply']) + elif not data['success']: + reply = 'Error: {reply}'.format(reply=data['reply']) else: - delta = time.time() - float(ctcp['reply']) + delta = time.time() - float(data['reply']) if delta < 1.0: delta *= 1000 unit = 'ms' else: unit = 's' reply = '{delta:.3f} {unit}'.format(unit=unit, delta=delta) - return '\x02[PING]\x0F {nick}: {text}'.format(nick=nick, text=reply) + + return self._ctcp('PING', nick, reply) @command async def finger(self, mask: IrcString, channel: IrcString, diff --git a/nxy/plugins/linux.py b/nxy/plugins/linux.py index d734d80..5b730b7 100644 --- a/nxy/plugins/linux.py +++ b/nxy/plugins/linux.py @@ -21,6 +21,11 @@ GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring class Linux(Plugin): KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml' + @irc3.event(r'(?i)^:\S+ PRIVMSG (?P\S+) :.*(debian|apt|dpkg).*') + def debillian(self, channel: str): + if random.randint(0, 3) is 0: + self.bot.privmsg(channel, 'REEEEEEEEEEEEEEEEEEEEEEEEEEEEE') + @irc3.event(r'(?i)^:\S+ PRIVMSG (?P\S+) :' r'.*(?... + %%ud ... """ - query = ' '.join(args.get('')).lower().strip().split() + term = ' '.join(args.get('')).lower().strip().split() - if query[-1].isdigit(): - idx = int(query[-1]) - 1 - query = ' '.join(query[:-1]) + if term[-1].isdigit(): + idx = int(term[-1]) - 1 + term = ' '.join(term[:-1]) else: idx = 0 - data = requests.get(self.URL, params=dict(term=query)).json() - + data = requests.get(self.URL, params=dict(term=term)).json() if data['result_type'] == 'no_results': - return '[UrbanDictionary] Query not found' - res = data['list'][idx] + return 'Term not found' - try: - return '[{idx}/{len}] \x02{word}\x02: {definition} - {example}' \ - .format(idx=idx + 1, - len=len(data['list']), - word=res['word'], - definition=res['definition'].replace('\r\n', ' '), - example=res['example'].replace('\r\n', ' ')) - except IndexError: - return '[UrbanDictionary] Error getting result' + res = data['list'][idx] + return '[{idx}/{len}] \x02{word}\x02: {definition} - {example}'.format( + idx=idx + 1, + len=len(data['list']), + word=res['word'], + definition=res['definition'].replace('\r\n', ' '), + example=res['example'].replace('\r\n', ' '), + ) diff --git a/nxy/plugins/useless.py b/nxy/plugins/useless.py index 24c06da..00de900 100644 --- a/nxy/plugins/useless.py +++ b/nxy/plugins/useless.py @@ -64,9 +64,9 @@ class Useless(Plugin): %%jn %%jn """ - choice = random.choice(['3Ja', '5Nein']) - return '{nick}: \x02\x03{choice}'.format(nick=mask.nick, - choice=choice) + choice = random.choice(['3Ja', '4Nein']) + return '{nick}: \x02\x03{choice}\x0F'.format(nick=mask.nick, + choice=choice) @command def kiss(self, mask: IrcString, channel: IrcString, args: DocOptDict): @@ -74,7 +74,7 @@ class Useless(Plugin): %%kiss """ - return '(づ。◕‿‿◕。)\x033。。・゜゜・。。・゜❤\x0F {nick} \x033❤'.format( + return '(づ。◕‿‿◕。)\x034。。・゜゜・。。・゜❤\x0F {nick} \x034❤'.format( nick=args['']) @command @@ -83,25 +83,25 @@ class Useless(Plugin): %%hug """ - return '\x033♥♡❤♡♥\x0F {nick} \x033♥♡❤♡♥'.format(nick=args['']) + return '\x034♥♡❤♡♥\x03 {nick} \x034♥♡❤♡♥'.format(nick=args['']) @command def bier(self, mask: IrcString, channel: IrcString, args: DocOptDict): """Gives nick a beer. - %%bier + %%bier [] """ - return '\x01ACTION schenkt ein kühles blondes an {nick} aus.\x01' \ - .format(nick=args['']) + self.bot.action(channel, 'schenkt ein kühles blondes an {nick} aus.' + .format(nick=args.get('') or mask.nick)) @command def fucken(self, mask: IrcString, channel: IrcString, args: DocOptDict): """Kills and fucks a nick. - %%fucken + %%fucken [] """ - return '\x01ACTION fuckt {nick} und tötet {nick} anschließend.\x01' \ - .format(nick=args['']) + self.bot.action(channel, 'fuckt {nick} und tötet {nick} anschließend.' + .format(nick=args.get('') or mask.nick)) @command def anhero(self, mask: IrcString, channel: IrcString, args: DocOptDict): diff --git a/nxy/plugins/youtube.py b/nxy/plugins/youtube.py index f742be7..305638d 100644 --- a/nxy/plugins/youtube.py +++ b/nxy/plugins/youtube.py @@ -41,9 +41,9 @@ class YouTube(Plugin): except ZeroDivisionError: score = 0 - return '{title} - length {length} -\x033 {likes:,}\x0F /\x035 ' \ - '{dislikes:,}\x0F ({score:,.1f}%) - {views:,} views - ' \ - '{channel} on {date}' \ + return '{title} - length {length} -\x033 {likes:,}\x03 /' \ + '\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \ + 'views - {channel} on {date}' \ .format(title=item['snippet']['title'], channel=item['snippet']['channelTitle'], length=' '.join([l.lower() for l in length]),