Compare commits
19 Commits
9c8203d433
...
master
Author | SHA1 | Date | |
---|---|---|---|
44b3fda6de | |||
f80c89ba09 | |||
132d6a19ca | |||
27c537b15a | |||
6a9bf7456b | |||
0edbc7a0f1 | |||
360fd4d164 | |||
91abf2bf93 | |||
3f7d1ae13c | |||
586a109a16 | |||
6986798245 | |||
b1100db649 | |||
1149417b56 | |||
f50fe88a14 | |||
fa51899a24 | |||
d59e170e8b | |||
cb1cc4439a | |||
ffa64f509c | |||
9ba11a50cd |
27
bot/ascii.py
27
bot/ascii.py
@ -9,33 +9,6 @@ from . import Plugin
|
||||
|
||||
class Ascii(Plugin):
|
||||
|
||||
@command
|
||||
def buddha(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""prints a giant swastika
|
||||
|
||||
%%buddha
|
||||
"""
|
||||
for line in (
|
||||
'░░░░░░░░░░░░░░░▄▀▄░░░░░░░░░░░░░░░',
|
||||
'░░░░░░░░░░░░░▄▀░░░▀▄░░░░░░░░░░░░░',
|
||||
'░░░░░░░░░░░▄▀░░░░▄▀█░░░░░░░░░░░░░',
|
||||
'░░░░░░░░░▄▀░░░░▄▀░▄▀░▄▀▄░░░░░░░░░',
|
||||
'░░░░░░░▄▀░░░░▄▀░▄▀░▄▀░░░▀▄░░░░░░░',
|
||||
'░░░░░░░█▀▄░░░░▀█░▄▀░░░░░░░▀▄░░░░░',
|
||||
'░░░▄▀▄░▀▄░▀▄░░░░▀░░░░▄█▄░░░░▀▄░░░',
|
||||
'░▄▀░░░▀▄░▀▄░▀▄░░░░░▄▀░█░▀▄░░░░▀▄░',
|
||||
'░█▀▄░░░░▀▄░█▀░░░░░░░▀█░▀▄░▀▄░▄▀█░',
|
||||
'░▀▄░▀▄░░░░▀░░░░▄█▄░░░░▀▄░▀▄░█░▄▀░',
|
||||
'░░░▀▄░▀▄░░░░░▄▀░█░▀▄░░░░▀▄░▀█▀░░░',
|
||||
'░░░░░▀▄░▀▄░▄▀░▄▀░█▀░░░░▄▀█░░░░░░░',
|
||||
'░░░░░░░▀▄░█░▄▀░▄▀░░░░▄▀░▄▀░░░░░░░',
|
||||
'░░░░░░░░░▀█▀░▄▀░░░░▄▀░▄▀░░░░░░░░░',
|
||||
'░░░░░░░░░░░░░█▀▄░▄▀░▄▀░░░░░░░░░░░',
|
||||
'░░░░░░░░░░░░░▀▄░█░▄▀░░░░░░░░░░░░░',
|
||||
'░░░░░░░░░░░░░░░▀█▀░░░░░░░░░░░░░░░'
|
||||
):
|
||||
self.bot.privmsg(target, line)
|
||||
|
||||
@command
|
||||
def rotschwuchtel(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""prints a giant hammer and sickle
|
||||
|
87
bot/coins.py
87
bot/coins.py
@ -10,12 +10,12 @@ def _currency(name, prefix=None, suffix=None):
|
||||
def tostr(value):
|
||||
return '{prefix}{value:,.2f}{suffix}'.format(
|
||||
prefix=prefix or '',
|
||||
suffix=suffix or ('' if (prefix or suffix) else (' ' + name)),
|
||||
suffix=suffix or ('' if (prefix or suffix) else (' ' + name.upper())),
|
||||
value=value)
|
||||
return tostr
|
||||
|
||||
class Coins(Plugin):
|
||||
API_URL = 'https://api.cryptowat.ch/markets/{market}/{crypto}{currency}/summary'
|
||||
API_URL = 'https://api.coingecko.com/api/v3/simple/price'
|
||||
|
||||
CURRENCIES = {
|
||||
'usd': _currency('usd', prefix='$'),
|
||||
@ -23,60 +23,89 @@ class Coins(Plugin):
|
||||
'eth': _currency('eth', suffix='Ξ'),
|
||||
'btc': _currency('btc', suffix='฿'),
|
||||
'xmr': _currency('xmr'),
|
||||
'xrp': _currency('xrp')
|
||||
}
|
||||
|
||||
CRYPTO_IDS = {
|
||||
'btc': 'bitcoin',
|
||||
'eth': 'ethereum',
|
||||
'xmr': 'monero',
|
||||
'xrp': 'ripple'
|
||||
}
|
||||
|
||||
@command
|
||||
def btc(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Gets the Bitcoin values from cryptowatch.
|
||||
"""Gets the Bitcoin values from coingecko.
|
||||
|
||||
%%btc [<currency>]
|
||||
"""
|
||||
return self.cryptowat_summary('btc', 'coinbase', args)
|
||||
return self.coingecko_summary('btc', args)
|
||||
|
||||
@command
|
||||
def eth(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Gets the Ethereum values from cryptowatch.
|
||||
"""Gets the Ethereum values from coingecko.
|
||||
|
||||
%%eth [<currency>]
|
||||
"""
|
||||
return self.cryptowat_summary('eth', 'coinbase', args)
|
||||
return self.coingecko_summary('eth', args)
|
||||
|
||||
@command
|
||||
def xmr(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Gets the Monero values from cryptowatch.
|
||||
"""Gets the Monero values from coingecko.
|
||||
|
||||
%%xmr [<currency>]
|
||||
"""
|
||||
return self.cryptowat_summary('xmr', 'bitfinex', args)
|
||||
return self.coingecko_summary('xmr', args)
|
||||
|
||||
@command
|
||||
def xrp(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Gets the Ripple values from coingecko.
|
||||
|
||||
%%xrp [<currency>]
|
||||
"""
|
||||
return self.coingecko_summary('xrp', args)
|
||||
|
||||
def coingecko_summary(self, crypto: str, args: Dict):
|
||||
crypto_id = self.CRYPTO_IDS.get(crypto)
|
||||
if crypto_id is None:
|
||||
raise ValueError
|
||||
|
||||
def cryptowat_summary(self, crypto: str, market: str, args: Dict):
|
||||
currency = args.get('<currency>', 'eur').lower()
|
||||
|
||||
def format_response(response: str) -> str:
|
||||
return f'\x02[{crypto.upper()}]\x02 {response}'
|
||||
|
||||
if currency not in self.CURRENCIES or crypto == currency:
|
||||
return '\x02[{}]\x02 Can\'t convert or invalid currency: {}'.format(crypto.upper(), currency)
|
||||
return format_response(f'Can\'t convert or invalid currency: {currency}')
|
||||
|
||||
def get_data(cur):
|
||||
return requests.get(self.API_URL.format(crypto=crypto, market=market, currency=cur))
|
||||
res = requests.get(self.API_URL, params={
|
||||
'ids': crypto_id,
|
||||
'vs_currencies': currency,
|
||||
'include_market_cap': 'true',
|
||||
'include_24hr_vol': 'true',
|
||||
'include_24hr_change': 'true'
|
||||
})
|
||||
|
||||
data = get_data(currency)
|
||||
if not data and currency != 'usd':
|
||||
data = get_data('usd')
|
||||
currency = 'usd'
|
||||
if not data:
|
||||
return '\x02[{}]\x02 No data received'.format(crypto)
|
||||
if res.status_code == 429:
|
||||
return format_response('Rate Limit exceeded')
|
||||
|
||||
if res.status_code != 200:
|
||||
return format_response('API Error')
|
||||
|
||||
data = res.json()[crypto_id]
|
||||
|
||||
if currency not in data:
|
||||
return format_response('No data received')
|
||||
|
||||
to_currency = self.CURRENCIES[currency]
|
||||
|
||||
result = data.json()['result']
|
||||
return '\x02[{crypto}]\x02 ' \
|
||||
'Current: \x02\x0307{last}\x0F - ' \
|
||||
'High: \x02\x0303{high}\x0F - ' \
|
||||
'Low: \x02\x0304{low}\x0F - ' \
|
||||
return format_response(
|
||||
'Price: \x02\x0307{price}\x0F - ' \
|
||||
'Change: \x02\x0307{change:,.2f}%\x0F - ' \
|
||||
'Volume: \x02\x0307{volume}\x0F' \
|
||||
'Volume: \x02\x0307{volume}\x0F - ' \
|
||||
'Market Cap: \x02\x0307{market_cap}\x0F' \
|
||||
.format(crypto=crypto.upper(),
|
||||
last=to_currency(result['price']['last']),
|
||||
high=to_currency(result['price']['high']),
|
||||
low=to_currency(result['price']['low']),
|
||||
change=result['price']['change']['percentage'] * 100,
|
||||
volume=result['volume'])
|
||||
price=to_currency(data[currency]),
|
||||
change=data[f'{currency}_24h_change'],
|
||||
volume=data[f'{currency}_24h_vol'],
|
||||
market_cap=to_currency(data[f'{currency}_market_cap'])))
|
||||
|
@ -113,4 +113,4 @@ class Drugs(Plugin):
|
||||
|
||||
%%meth [<nick>]
|
||||
"""
|
||||
self.bot.action(target, 'legt {} eine dicke Line Meth \________'.format(args.get('<nick>', mask.nick)))
|
||||
self.bot.action(target, r'legt {} eine dicke Line Meth \________'.format(args.get('<nick>', mask.nick)))
|
||||
|
30
bot/linux.py
30
bot/linux.py
@ -2,7 +2,7 @@
|
||||
import random
|
||||
|
||||
import irc3
|
||||
import feedparser
|
||||
import requests
|
||||
from docopt import Dict
|
||||
from irc3.plugins.command import command
|
||||
from irc3.utils import IrcString
|
||||
@ -19,18 +19,18 @@ OS as defined by POSIX."""
|
||||
|
||||
|
||||
class Linux(Plugin):
|
||||
KERNEL_FEED = 'https://www.kernel.org/feeds/kdist.xml'
|
||||
KERNEL_FEED = 'https://www.kernel.org/releases.json'
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :(?:.* )?(debian|ubuntu|apt|dpkg|flash)(?: .*|$)')
|
||||
def debillian(self, target: str):
|
||||
"""Annoying RE trigger for debian with variable count of E."""
|
||||
if random.randint(0, 3) is 0:
|
||||
if random.randint(0, 3) == 0:
|
||||
self.bot.privmsg(target, re_generator())
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?<!gnu[/+])linux(?! kernel).*')
|
||||
def linux(self, target: str):
|
||||
"""Super annoying, useless 'Stallman is mad' trigger."""
|
||||
if random.randint(0, 12) is 0:
|
||||
if random.randint(0, 12) == 0:
|
||||
self.bot.privmsg(target, GNU_LINUX)
|
||||
|
||||
@command
|
||||
@ -39,21 +39,17 @@ class Linux(Plugin):
|
||||
|
||||
%%kernel
|
||||
"""
|
||||
feed = feedparser.parse(self.KERNEL_FEED)
|
||||
|
||||
# Cancel if no feed or entries
|
||||
if not feed or not feed.get('entries'):
|
||||
self.log.error('Error fetching kernel.org releases feed')
|
||||
return
|
||||
try:
|
||||
res = requests.get(self.KERNEL_FEED, timeout=10).json()
|
||||
except requests.exceptions.RequestException:
|
||||
return '\x02[Kernel]\x02 Error fetching kernel.org releases'
|
||||
except requests.exceptions.JSONDecodeError:
|
||||
return '\x02[Kernel]\x02 Error decoding kernel.org releases'
|
||||
|
||||
# Make list of releases
|
||||
releases = []
|
||||
for e in feed['entries']:
|
||||
version, branch = e['title'].split(': ')
|
||||
|
||||
if '(EOL)' in e['description']:
|
||||
branch = '{}, \x1DEOL\x1D'.format(branch)
|
||||
|
||||
releases.append('\x02{}\x02 ({})'.format(version, branch))
|
||||
for release in res['releases']:
|
||||
releases.append('\x02{}\x02 ({}{})'.format(release['version'], release['moniker'],
|
||||
', \x1DEOL\x1D' if release['iseol'] else ''))
|
||||
|
||||
return '\x02[Kernel]\x02 {}'.format(', '.join(releases))
|
||||
|
@ -66,4 +66,4 @@ class McManiac(DatabasePlugin):
|
||||
result = cur.fetchone()
|
||||
if result is None:
|
||||
return
|
||||
self.bot.privmsg(channel, f"{result['total']}. mcmanic added: {item}")
|
||||
self.bot.privmsg(channel, f"{result['total']}. mcmaniac added: {item}")
|
||||
|
@ -87,7 +87,7 @@ class Quotes(DatabasePlugin):
|
||||
self.con.commit()
|
||||
except Error as ex:
|
||||
# Rollback transaction on error
|
||||
print(ex)
|
||||
self.log.error(ex)
|
||||
self.con.rollback()
|
||||
else:
|
||||
query = None
|
||||
|
@ -9,17 +9,17 @@ from . import Plugin
|
||||
|
||||
class URLInfo(Plugin):
|
||||
BLACKLIST = [
|
||||
"^https?:\/\/(?:www\.)?youtube\.com",
|
||||
"^https?:\/\/youtu\.be",
|
||||
"^https?:\/\/w0bm\.com",
|
||||
"^https?:\/\/f0ck\.me",
|
||||
"^https?:\/\/(?:(?:vid|img|thumb)\.)?pr0gramm\.com"
|
||||
r"^https?:\/\/(?:www\.)?youtube\.com",
|
||||
r"^https?:\/\/youtu\.be",
|
||||
r"^https?:\/\/w0bm\.com",
|
||||
r"^https?:\/\/f0ck\.me",
|
||||
r"^https?:\/\/(?:(?:vid|img|thumb)\.)?pr0gramm\.com"
|
||||
]
|
||||
|
||||
# set the size limit to 2 MB so we don't fully download too large resources
|
||||
SIZE_LIMIT = 2 * 1024 ** 2
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?P<url>https?:\/\/\S+\.\S+).*')
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*?(?P<url>https?:\/\/\S+\.\S+).*')
|
||||
def url_parser(self, target: str, url: str):
|
||||
for regex in self.BLACKLIST:
|
||||
if re.match(regex, url):
|
||||
@ -39,7 +39,7 @@ class URLInfo(Plugin):
|
||||
if size >= self.SIZE_LIMIT:
|
||||
return
|
||||
bytes_io.write(chunk)
|
||||
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.ReadTimeout, requests.exceptions.TooManyRedirects):
|
||||
except requests.exceptions.RequestException:
|
||||
return
|
||||
|
||||
bytes_io.seek(0)
|
||||
|
@ -471,14 +471,6 @@ class Useless(DatabasePlugin):
|
||||
nick = args.get('<nick>', mask.nick)
|
||||
self.bot.action(target, 'hustet {0} in\'s Gesicht'.format(nick, nick))
|
||||
|
||||
@command
|
||||
def vampir(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Sends a url with the cute vampire cat :3
|
||||
|
||||
%%vampir
|
||||
"""
|
||||
return 'https://files.catbox.moe/ma2dfs.png'
|
||||
|
||||
@command
|
||||
def hebamme(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Tells you to get the fuck outta this group
|
||||
|
@ -15,7 +15,7 @@ from .utils import date_from_iso
|
||||
class YouTube(Plugin):
|
||||
URL = 'https://www.googleapis.com/youtube/v3'
|
||||
API = '{}/videos?part=snippet,statistics,contentDetails'.format(URL)
|
||||
SEARCH = '{}/search?part=id'.format(URL)
|
||||
SEARCH = '{}/search?type=video&maxResults=1&part=id'.format(URL)
|
||||
RETURN_YOUTUBE_DISLIKE_API = 'https://returnyoutubedislikeapi.com/votes'
|
||||
|
||||
def get_video_data(self, video_id: str):
|
||||
@ -29,7 +29,7 @@ class YouTube(Plugin):
|
||||
|
||||
item = data['items'][0]
|
||||
date = date_from_iso(item['snippet']['publishedAt'])
|
||||
length = re.findall('(\d+[DHMS])', item['contentDetails']['duration'])
|
||||
length = re.findall(r'(\d+[DHMS])', item['contentDetails']['duration'])
|
||||
|
||||
views = int(item['statistics'].get('viewCount', 0))
|
||||
likes = int(item['statistics'].get('likeCount', 0))
|
||||
@ -53,7 +53,7 @@ class YouTube(Plugin):
|
||||
views=views,
|
||||
date=date.strftime('%d.%m.%Y %H:%M:%S UTC'))
|
||||
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?:youtube.*?(?:v=|/v/)'
|
||||
@irc3.event(r'(?i)^:\S+ PRIVMSG (?P<target>\S+) :.*(?:youtube.*?(?:v=|/v/|/live/|/shorts/)'
|
||||
r'|youtu\.be/)(?P<video_id>[-_a-zA-Z0-9]+).*')
|
||||
def youtube_parser(self, target: str, video_id: str):
|
||||
data = self.get_video_data(video_id)
|
||||
@ -70,7 +70,7 @@ class YouTube(Plugin):
|
||||
|
||||
if 'error' in data:
|
||||
return '\x02[YouTube]\x02 Error performing search'
|
||||
elif data['pageInfo']['totalResults'] is 0:
|
||||
elif data['pageInfo']['totalResults'] == 0:
|
||||
return '\x02[YouTube]\x02 No results found'
|
||||
else:
|
||||
video_id = data['items'][0]['id']['videoId']
|
||||
|
@ -6,6 +6,5 @@ aiocron~=1.3
|
||||
psycopg2~=2.8
|
||||
requests~=2.22
|
||||
GitPython~=3.0
|
||||
feedparser~=5.2
|
||||
python-dotenv~=0.17.1
|
||||
lxml~=4.6
|
||||
lxml~=5.3
|
||||
|
Reference in New Issue
Block a user