This commit is contained in:
mrhanky 2017-06-01 17:38:34 +02:00
parent fb4e7b2d5b
commit e69307283d
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
8 changed files with 67 additions and 62 deletions

View File

@ -21,10 +21,10 @@ class Coins(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 '\x02[BitStamp]\x02 ' \ return '\x02[Bitcoin]\x02 ' \
'Current: \x02\x037${last:,.2f}\x0F - ' \ 'Current: \x02\x037${last:,.2f}\x0F - ' \
'High: \x02\x033${high:,.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) 'Volume: \x02฿{volume:,.2f}\x02'.format(**values)
@command @command

View File

@ -14,24 +14,28 @@ class CTCP(Plugin):
requires = ['irc3.plugins.async', requires = ['irc3.plugins.async',
'irc3.plugins.command'] 'irc3.plugins.command']
TIMEOUT = 10 @staticmethod
def _ctcp(name: str, nick: str, reply: str):
async def ctcp(self, ctcp: str, mask: IrcString, args: DocOptDict): return '\x02[{name}]\x02 {nick}: {reply}'.format(
nick = args.get('<nick>') or mask.nick name=name.upper(),
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,
nick=nick, nick=nick,
reply=reply, reply=reply,
) )
async def ctcp(self, name: str, mask: IrcString, args: DocOptDict):
nick = args.get('<nick>') 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 @command
async def ping(self, mask: IrcString, channel: IrcString, async def ping(self, mask: IrcString, channel: IrcString,
args: DocOptDict): args: DocOptDict):
@ -40,21 +44,22 @@ class CTCP(Plugin):
%%ping [<nick>] %%ping [<nick>]
""" """
nick = args.get('<nick>') or mask.nick nick = args.get('<nick>') or mask.nick
ctcp = await self.bot.ctcp_async(nick, 'PING {0}'.format(time.time()), data = await self.bot.ctcp_async(nick, 'PING {0}'.format(time.time()))
timeout=self.TIMEOUT)
if not ctcp or ctcp['timeout']: if not data or data['timeout']:
reply = 'timeout' reply = 'timeout'
elif not ctcp['success']: elif not data['success']:
reply = 'Error: {reply}'.format(reply=ctcp['reply']) reply = 'Error: {reply}'.format(reply=data['reply'])
else: else:
delta = time.time() - float(ctcp['reply']) delta = time.time() - float(data['reply'])
if delta < 1.0: if delta < 1.0:
delta *= 1000 delta *= 1000
unit = 'ms' unit = 'ms'
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 '\x02[PING]\x0F {nick}: {text}'.format(nick=nick, text=reply)
return self._ctcp('PING', nick, reply)
@command @command
async def finger(self, mask: IrcString, channel: IrcString, async def finger(self, mask: IrcString, channel: IrcString,

View File

@ -21,6 +21,11 @@ GNU_LINUX = """I'd Just Like To Interject For A Moment. What you're referring
class Linux(Plugin): class Linux(Plugin):
KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml' KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml'
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\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<channel>\S+) :' @irc3.event(r'(?i)^:\S+ PRIVMSG (?P<channel>\S+) :'
r'.*(?<!gnu[/+])linux(?! kernel).*') r'.*(?<!gnu[/+])linux(?! kernel).*')
def linux(self, channel: str): def linux(self, channel: str):
@ -38,8 +43,8 @@ class Linux(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 = '{branch}, \x1DEOL\x0F'.format(branch=branch) branch = '{branch}, \x1DEOL\x1D'.format(branch=branch)
releases.append('\x02{version}\x0F ({branch})'.format( releases.append('\x02{version}\x02 ({branch})'.format(
version=version, version=version,
branch=branch, branch=branch,
)) ))

View File

@ -27,7 +27,7 @@ class Rape(DatabasePlugin):
owes = self.cur.fetchone() owes = self.cur.fetchone()
if owes: if owes:
total = '5${total}'.format(total=owes['amount']) total = '4${total}'.format(total=owes['amount'])
else: else:
total = '3$0' total = '3$0'

View File

@ -10,6 +10,7 @@ from irc3.utils import IrcString
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Seen(DatabasePlugin): class Seen(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'nxy.plugins.database'] 'nxy.plugins.database']

View File

@ -1,7 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import irc3 import irc3
import os
import re
import requests import requests
from docopt import Dict as DocOptDict from docopt import Dict as DocOptDict
@ -9,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 date_from_iso
@irc3.plugin @irc3.plugin
@ -20,30 +17,27 @@ class Urban(Plugin):
@command @command
def ud(self, mask: IrcString, channel: IrcString, args: DocOptDict): def ud(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Searches for query on YouTube and returns first result. """Searches for a term on YouTube and returns first result.
%%ud <query>... %%ud <term>...
""" """
query = ' '.join(args.get('<query>')).lower().strip().split() term = ' '.join(args.get('<term>')).lower().strip().split()
if query[-1].isdigit(): if term[-1].isdigit():
idx = int(query[-1]) - 1 idx = int(term[-1]) - 1
query = ' '.join(query[:-1]) term = ' '.join(term[:-1])
else: else:
idx = 0 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': if data['result_type'] == 'no_results':
return '[UrbanDictionary] Query not found' return 'Term not found'
res = data['list'][idx]
try: res = data['list'][idx]
return '[{idx}/{len}] \x02{word}\x02: {definition} - {example}' \ return '[{idx}/{len}] \x02{word}\x02: {definition} - {example}'.format(
.format(idx=idx + 1, idx=idx + 1,
len=len(data['list']), len=len(data['list']),
word=res['word'], word=res['word'],
definition=res['definition'].replace('\r\n', ' '), definition=res['definition'].replace('\r\n', ' '),
example=res['example'].replace('\r\n', ' ')) example=res['example'].replace('\r\n', ' '),
except IndexError: )
return '[UrbanDictionary] Error getting result'

View File

@ -64,8 +64,8 @@ class Useless(Plugin):
%%jn <question> %%jn <question>
%%jn %%jn
""" """
choice = random.choice(['3Ja', '5Nein']) choice = random.choice(['3Ja', '4Nein'])
return '{nick}: \x02\x03{choice}'.format(nick=mask.nick, return '{nick}: \x02\x03{choice}\x0F'.format(nick=mask.nick,
choice=choice) choice=choice)
@command @command
@ -74,7 +74,7 @@ class Useless(Plugin):
%%kiss <nick> %%kiss <nick>
""" """
return '(づ。◕‿‿◕。)\x033。。・゜゜・。。・゜❤\x0F {nick} \x033'.format( return '(づ。◕‿‿◕。)\x034。。・゜゜・。。・゜❤\x0F {nick} \x034'.format(
nick=args['<nick>']) nick=args['<nick>'])
@command @command
@ -83,25 +83,25 @@ class Useless(Plugin):
%%hug <nick> %%hug <nick>
""" """
return '\x033♥♡❤♡♥\x0F {nick} \x033♥♡❤♡♥'.format(nick=args['<nick>']) return '\x034♥♡❤♡♥\x03 {nick} \x034♥♡❤♡♥'.format(nick=args['<nick>'])
@command @command
def bier(self, mask: IrcString, channel: IrcString, args: DocOptDict): def bier(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Gives nick a beer. """Gives nick a beer.
%%bier <nick> %%bier [<nick>]
""" """
return '\x01ACTION schenkt ein kühles blondes an {nick} aus.\x01' \ self.bot.action(channel, 'schenkt ein kühles blondes an {nick} aus.'
.format(nick=args['<nick>']) .format(nick=args.get('<nick>') or mask.nick))
@command @command
def fucken(self, mask: IrcString, channel: IrcString, args: DocOptDict): def fucken(self, mask: IrcString, channel: IrcString, args: DocOptDict):
"""Kills and fucks a nick. """Kills and fucks a nick.
%%fucken <nick> %%fucken [<nick>]
""" """
return '\x01ACTION fuckt {nick} und tötet {nick} anschließend.\x01' \ self.bot.action(channel, 'fuckt {nick} und tötet {nick} anschließend.'
.format(nick=args['<nick>']) .format(nick=args.get('<nick>') or mask.nick))
@command @command
def anhero(self, mask: IrcString, channel: IrcString, args: DocOptDict): def anhero(self, mask: IrcString, channel: IrcString, args: DocOptDict):

View File

@ -41,9 +41,9 @@ class YouTube(Plugin):
except ZeroDivisionError: except ZeroDivisionError:
score = 0 score = 0
return '{title} - length {length} -\x033 {likes:,}\x0F /\x035 ' \ return '{title} - length {length} -\x033 {likes:,}\x03 /' \
'{dislikes:,}\x0F ({score:,.1f}%) - {views:,} views - ' \ '\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \
'{channel} on {date}' \ 'views - {channel} on {date}' \
.format(title=item['snippet']['title'], .format(title=item['snippet']['title'],
channel=item['snippet']['channelTitle'], channel=item['snippet']['channelTitle'],
length=' '.join([l.lower() for l in length]), length=' '.join([l.lower() for l in length]),