CONSISTENCY! Removed all dots in docs, removed blank lines and useless try/except, uppercased all sql statements
This commit is contained in:
parent
6f36c7ed9f
commit
a931d31e39
|
@ -17,7 +17,7 @@ class Useless(DatabasePlugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def isup(self, mask: IrcString, target: IrcString, args: Dict):
|
def isup(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Checks if a address is up.
|
"""Checks if a address is up or down
|
||||||
|
|
||||||
%%isup <address>
|
%%isup <address>
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -10,7 +10,6 @@ from irc3.utils import IrcString
|
||||||
from . import Plugin
|
from . import Plugin
|
||||||
from ..utils import re_generator
|
from ..utils import re_generator
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it,
|
to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it,
|
||||||
GNU plus Linux. Linux is not an operating system unto itself, but rather
|
GNU plus Linux. Linux is not an operating system unto itself, but rather
|
||||||
|
@ -36,7 +35,7 @@ class Linux(Plugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def kernel(self, mask: IrcString, target: IrcString, args: Dict):
|
def kernel(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Get Linux kernel releases.
|
"""Get Linux kernel releases
|
||||||
|
|
||||||
%%kernel
|
%%kernel
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -61,9 +61,9 @@ class McManiac(DatabasePlugin):
|
||||||
try:
|
try:
|
||||||
# Insert into database
|
# Insert into database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
INSERT INTO
|
||||||
mcmaniacs (item)
|
mcmaniacs (item)
|
||||||
values
|
VALUES
|
||||||
(%s)
|
(%s)
|
||||||
''', [item])
|
''', [item])
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Quotes(DatabasePlugin):
|
||||||
requires = ['irc3.plugins.command',
|
requires = ['irc3.plugins.command',
|
||||||
'bot.plugins.storage']
|
'bot.plugins.storage']
|
||||||
|
|
||||||
def add_quote(self, mask, nick, quote, channel):
|
def add_quote(self, mask: IrcString, nick: str, quote: str, channel: IrcString):
|
||||||
# Parse nick from "<@foobar>" like strings
|
# Parse nick from "<@foobar>" like strings
|
||||||
nick = re.match(r'<?[~&@%+]?([a-zA-Z0-9_\-^`|\\\[\]{}]+)>?', nick).group(1)
|
nick = re.match(r'<?[~&@%+]?([a-zA-Z0-9_\-^`|\\\[\]{}]+)>?', nick).group(1)
|
||||||
|
|
||||||
|
@ -31,38 +31,40 @@ class Quotes(DatabasePlugin):
|
||||||
(%s, %s, %s, %s)
|
(%s, %s, %s, %s)
|
||||||
''', [nick, quote, channel, mask.nick])
|
''', [nick, quote, channel, mask.nick])
|
||||||
|
|
||||||
def delete_quote(self, nick, quote):
|
def delete_quote(self, nick: str, quote: str):
|
||||||
index, order = parse_int(quote, select=False)
|
index, order = parse_int(quote, select=False)
|
||||||
|
|
||||||
if index:
|
if index:
|
||||||
# Delete from database
|
# Delete from database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
with ranked_quotes as (
|
-- noinspection SqlResolve
|
||||||
select
|
WITH ranked_quotes AS (
|
||||||
|
SELECT
|
||||||
id,
|
id,
|
||||||
rank() over (partition by nick order by id {order})
|
rank() OVER (PARTITION BY nick ORDER BY id {order})
|
||||||
from
|
FROM
|
||||||
quotes
|
quotes
|
||||||
where
|
WHERE
|
||||||
nick = %s
|
lower(nick) = lower(%s)
|
||||||
)
|
)
|
||||||
|
|
||||||
delete from
|
-- noinspection SqlResolve
|
||||||
|
DELETE FROM
|
||||||
quotes
|
quotes
|
||||||
where
|
WHERE
|
||||||
id = (
|
id = (
|
||||||
select
|
SELECT
|
||||||
id
|
id
|
||||||
from
|
FROM
|
||||||
ranked_quotes
|
ranked_quotes
|
||||||
where
|
WHERE
|
||||||
rank = %s
|
rank = %s
|
||||||
)
|
)
|
||||||
'''.format(order=order), [nick, index])
|
'''.format(order=order), [nick, index])
|
||||||
|
|
||||||
@command(options_first=True)
|
@command(options_first=True)
|
||||||
def q(self, mask: IrcString, target: IrcString, args: Dict):
|
def q(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Get, add or delete quotes for an user.
|
"""Get, add or delete quotes for an user
|
||||||
|
|
||||||
%%q <cmd> <nick> <quote>...
|
%%q <cmd> <nick> <quote>...
|
||||||
%%q <nick> [<index>]
|
%%q <nick> [<index>]
|
||||||
|
@ -95,36 +97,36 @@ class Quotes(DatabasePlugin):
|
||||||
return
|
return
|
||||||
index, order = index
|
index, order = index
|
||||||
order = 'rank {order}'.format(order=order)
|
order = 'rank {order}'.format(order=order)
|
||||||
offset = 'offset %s'
|
offset = 'OFFSET %s'
|
||||||
values.append(index)
|
values.append(index)
|
||||||
else:
|
else:
|
||||||
order = 'random()'
|
order = 'random()'
|
||||||
offset = ''
|
offset = ''
|
||||||
|
|
||||||
# Fetch quote from database
|
# Fetch quote from database
|
||||||
self.cur.execute("""
|
self.cur.execute('''
|
||||||
with ranked_quotes as (
|
WITH ranked_quotes AS (
|
||||||
select
|
SELECT
|
||||||
nick,
|
nick,
|
||||||
item,
|
item,
|
||||||
rank() over (partition by nick order by id),
|
rank() OVER (PARTITION BY nick ORDER BY id),
|
||||||
count(*) over (partition by nick) as total
|
count(*) OVER (PARTITION BY nick) AS total
|
||||||
from
|
FROM
|
||||||
quotes
|
quotes
|
||||||
)
|
)
|
||||||
|
|
||||||
select
|
SELECT
|
||||||
*
|
*
|
||||||
from
|
FROM
|
||||||
ranked_quotes
|
ranked_quotes
|
||||||
where
|
WHERE
|
||||||
lower(nick) like lower(%s)
|
lower(nick) LIKE lower(%s)
|
||||||
order by
|
ORDER BY
|
||||||
{order}
|
{order}
|
||||||
limit
|
LIMIT
|
||||||
1
|
1
|
||||||
{offset}
|
{offset}
|
||||||
""".format(order=order, offset=offset), values)
|
'''.format(order=order, offset=offset), values)
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
|
|
|
@ -5,7 +5,6 @@ import irc3
|
||||||
from docopt import Dict
|
from docopt import Dict
|
||||||
from irc3.plugins.command import command
|
from irc3.plugins.command import command
|
||||||
from irc3.utils import IrcString
|
from irc3.utils import IrcString
|
||||||
from psycopg2 import Error
|
|
||||||
|
|
||||||
from . import DatabasePlugin
|
from . import DatabasePlugin
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ class Rape(DatabasePlugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def owe(self, mask: IrcString, target: IrcString, args: Dict):
|
def owe(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Shows how much a nick owes.
|
"""Shows how much a nick owes
|
||||||
|
|
||||||
%%owe [<nick>]
|
%%owe [<nick>]
|
||||||
"""
|
"""
|
||||||
|
@ -25,11 +24,11 @@ class Rape(DatabasePlugin):
|
||||||
|
|
||||||
# Fetch result from database
|
# Fetch result from database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
fines
|
fines
|
||||||
from
|
FROM
|
||||||
users
|
users
|
||||||
where
|
WHERE
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
owes = self.cur.fetchone()
|
owes = self.cur.fetchone()
|
||||||
|
@ -45,7 +44,7 @@ class Rape(DatabasePlugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def rape(self, mask: IrcString, target: IrcString, args: Dict):
|
def rape(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Rapes a nick and eventually charge for it.
|
"""Rapes a nick and eventually charge for it
|
||||||
|
|
||||||
%%rape <nick>
|
%%rape <nick>
|
||||||
"""
|
"""
|
||||||
|
@ -57,31 +56,26 @@ class Rape(DatabasePlugin):
|
||||||
else:
|
else:
|
||||||
fine = random.randint(1, 500)
|
fine = random.randint(1, 500)
|
||||||
|
|
||||||
try:
|
# Insert or add fine to database and return total owe
|
||||||
# Insert or add fine to database and return total owe
|
self.cur.execute('''
|
||||||
self.cur.execute('''
|
INSERT INTO
|
||||||
insert into
|
users (nick, fines)
|
||||||
users (nick, fines)
|
VALUES
|
||||||
values
|
(lower(%s), %s)
|
||||||
(lower(%s), %s)
|
ON CONFLICT (nick) DO UPDATE SET
|
||||||
on conflict (nick) do update set
|
fines = users.fines + excluded.fines
|
||||||
fines = users.fines + excluded.fines
|
RETURNING
|
||||||
returning
|
fines
|
||||||
fines
|
''', [mask.nick, fine])
|
||||||
''', [mask.nick, fine])
|
self.con.commit()
|
||||||
self.con.commit()
|
|
||||||
|
|
||||||
# Get reason based on rand value
|
# Get reason based on rand value
|
||||||
reason = ('raping', 'being too lewd and getting raped')[rand]
|
reason = ('raping', 'being too lewd and getting raped')[rand]
|
||||||
|
|
||||||
# Print fine and total owe
|
# Print fine and total owe
|
||||||
self.bot.action(target,
|
self.bot.action(target, 'fines {nick} \x02${fine}\x02 for {reason}. You owe: \x0304${total}\x03'.format(
|
||||||
'fines {nick} \x02${fine}\x02 for {reason}. '
|
nick=mask.nick,
|
||||||
'You owe: \x0304${total}\x03'
|
fine=fine,
|
||||||
.format(nick=mask.nick,
|
reason=reason,
|
||||||
fine=fine,
|
total=self.cur.fetchone()['fines'],
|
||||||
reason=reason,
|
))
|
||||||
total=self.cur.fetchone()['fines']))
|
|
||||||
except Error:
|
|
||||||
# Rollback transaction on error
|
|
||||||
self.con.rollback()
|
|
||||||
|
|
|
@ -16,21 +16,20 @@ class Useless(DatabasePlugin):
|
||||||
r'(?P<search>(?:[^/\\]|\\.)*)/'
|
r'(?P<search>(?:[^/\\]|\\.)*)/'
|
||||||
r'(?P<replace>(?:.*?))'
|
r'(?P<replace>(?:.*?))'
|
||||||
r'(?:/ ?(?P<nick>.*))?$')
|
r'(?:/ ?(?P<nick>.*))?$')
|
||||||
def regex(self, mask: str, target: str, search: str, replace: str,
|
def regex(self, mask: str, target: str, search: str, replace: str, nick: str = None):
|
||||||
nick: str = None):
|
|
||||||
nick = (nick or IrcString(mask).nick).strip()
|
nick = (nick or IrcString(mask).nick).strip()
|
||||||
|
|
||||||
if nick == self.bot.nick:
|
if nick == self.bot.nick:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
item
|
item
|
||||||
from
|
FROM
|
||||||
last_messages
|
last_messages
|
||||||
where
|
WHERE
|
||||||
nick = lower(%s)
|
nick = lower(%s)
|
||||||
and channel = lower(%s)
|
AND channel = lower(%s)
|
||||||
''', [nick, target])
|
''', [nick, target])
|
||||||
result = self.cur.fetchone()
|
result = self.cur.fetchone()
|
||||||
|
|
||||||
|
@ -48,11 +47,11 @@ class Useless(DatabasePlugin):
|
||||||
mask = IrcString(mask)
|
mask = IrcString(mask)
|
||||||
|
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
insert into
|
INSERT INTO
|
||||||
last_messages (nick, host, channel, item)
|
last_messages (nick, host, channel, item)
|
||||||
values
|
VALUES
|
||||||
(lower(%s), %s, lower(%s), %s)
|
(lower(%s), %s, lower(%s), %s)
|
||||||
on conflict (nick, channel) do update set
|
ON CONFLICT (nick, channel) DO UPDATE SET
|
||||||
host = excluded.host,
|
host = excluded.host,
|
||||||
item = excluded.item
|
item = excluded.item
|
||||||
''', [mask.nick, mask.host, target, msg])
|
''', [mask.nick, mask.host, target, msg])
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
import irc3
|
import irc3
|
||||||
from docopt import Dict
|
from docopt import Dict
|
||||||
from irc3.plugins.command import command
|
from irc3.plugins.command import command
|
||||||
from irc3.utils import IrcString
|
from irc3.utils import IrcString
|
||||||
from psycopg2 import Error
|
|
||||||
|
|
||||||
from . import DatabasePlugin
|
from . import DatabasePlugin
|
||||||
|
|
||||||
|
@ -18,7 +16,7 @@ class Seen(DatabasePlugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def seen(self, mask: IrcString, target: IrcString, args: Dict):
|
def seen(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Get last seen date and message for a nick.
|
"""Get last seen date and message for a nick
|
||||||
|
|
||||||
%%seen [<nick>]
|
%%seen [<nick>]
|
||||||
"""
|
"""
|
||||||
|
@ -26,22 +24,22 @@ class Seen(DatabasePlugin):
|
||||||
|
|
||||||
# Don't be stupid
|
# Don't be stupid
|
||||||
if nick == mask.nick:
|
if nick == mask.nick:
|
||||||
return '{nick}, have you seen in the mirror?'.format(nick=nick)
|
return '{}, look in the mirror faggot!'.format(nick)
|
||||||
|
|
||||||
# Fetch seen from database
|
# Fetch seen from database
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
select
|
SELECT
|
||||||
*
|
*
|
||||||
from
|
FROM
|
||||||
seens
|
seens
|
||||||
where
|
WHERE
|
||||||
lower(nick) = lower(%s)
|
lower(nick) = lower(%s)
|
||||||
''', [nick])
|
''', [nick])
|
||||||
seen = self.cur.fetchone()
|
seen = self.cur.fetchone()
|
||||||
|
|
||||||
# No result
|
# No result
|
||||||
if not seen:
|
if not seen:
|
||||||
return 'I\'ve never seen {nick}'.format(nick=nick)
|
return 'I\'ve never seen {}'.format(nick)
|
||||||
|
|
||||||
# Return result
|
# Return result
|
||||||
return '{nick} was last seen {delta} saying: {message}'.format(
|
return '{nick} was last seen {delta} saying: {message}'.format(
|
||||||
|
@ -55,20 +53,15 @@ class Seen(DatabasePlugin):
|
||||||
def save(self, mask: str, target: str, msg: str):
|
def save(self, mask: str, target: str, msg: str):
|
||||||
mask = IrcString(mask)
|
mask = IrcString(mask)
|
||||||
|
|
||||||
try:
|
self.cur.execute('''
|
||||||
# Insert or update if user writes a message
|
INSERT INTO
|
||||||
self.cur.execute('''
|
seens (nick, host, channel, message)
|
||||||
insert into
|
VALUES
|
||||||
seens (nick, host, channel, message, seen_at)
|
(%s, %s, %s, %s)
|
||||||
values
|
ON CONFLICT (nick) DO UPDATE SET
|
||||||
(%s, %s, %s, %s, %s)
|
host = excluded.host,
|
||||||
on conflict (nick) do update set
|
channel = excluded.channel,
|
||||||
host = excluded.host,
|
seen_at = now(),
|
||||||
channel = excluded.channel,
|
message = excluded.message
|
||||||
seen_at = excluded.seen_at,
|
''', [mask.nick, mask.host, target, msg])
|
||||||
message = excluded.message
|
self.con.commit()
|
||||||
''', [mask.nick, mask.host, target, msg, datetime.now()])
|
|
||||||
self.con.commit()
|
|
||||||
except Error:
|
|
||||||
# Rollback transaction on error
|
|
||||||
self.con.rollback()
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Tell(DatabasePlugin):
|
||||||
if nick in self.tell_queue:
|
if nick in self.tell_queue:
|
||||||
# Forward all tells for nick
|
# Forward all tells for nick
|
||||||
for tell in self.tell_queue[nick]:
|
for tell in self.tell_queue[nick]:
|
||||||
self.bot.privmsg(nick, '[Tell] Message from {nick} at {time}: {message}'.format(
|
self.bot.privmsg(nick, '\x02[Tell]\x02 Message from {nick} at {time}: {message}'.format(
|
||||||
nick=tell[0],
|
nick=tell[0],
|
||||||
time=tell[1], # TODO: format time
|
time=tell[1], # TODO: format time
|
||||||
message=tell[2],
|
message=tell[2],
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Urban(Plugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def ud(self, mask: IrcString, target: IrcString, args: Dict):
|
def ud(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Searches for a term on YouTube and returns first result.
|
"""Searches for a term on YouTube and returns first result
|
||||||
|
|
||||||
%%ud <term>...
|
%%ud <term>...
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -18,21 +18,22 @@ class Weather(Plugin):
|
||||||
|
|
||||||
@command
|
@command
|
||||||
def weather(self, mask: IrcString, target: IrcString, args: Dict):
|
def weather(self, mask: IrcString, target: IrcString, args: Dict):
|
||||||
"""Gets the weather from Yahoo weather API.
|
"""Gets the weather from Yahoo weather API
|
||||||
|
|
||||||
%%weather <location>...
|
%%weather <location>...
|
||||||
"""
|
"""
|
||||||
req = requests.get(self.URL.format(' '.join(args['<location>'])))
|
req = requests.get(self.URL.format(' '.join(args['<location>'])))
|
||||||
data = req.json()
|
data = req.json()
|
||||||
|
|
||||||
if 'error' in data:
|
if 'error' in data:
|
||||||
return '\x02[Weather]\x0F Error'
|
return '\x02[Weather]\x02 Error'
|
||||||
elif not data['query']['results']:
|
elif not data['query']['results']:
|
||||||
return '\x02[Weather]\x0F Location not found'
|
return '\x02[Weather]\x02 Location not found'
|
||||||
else:
|
else:
|
||||||
res = data['query']['results']['channel']
|
res = data['query']['results']['channel']
|
||||||
return '\x02[Weather]\x0F {city}, {region}, {country}: ' \
|
return '\x02[Weather]\x02 {city}, {region}, {country}: ' \
|
||||||
'\x02{temp}°{unit_temp} {text}\x0F, ' \
|
'\x02{temp}°{unit_temp} {text}\x02, ' \
|
||||||
'\x02{direction} {speed} {unit_speed}\x0F' \
|
'\x02{direction} {speed} {unit_speed}\x02' \
|
||||||
.format(city=res['location']['city'],
|
.format(city=res['location']['city'],
|
||||||
region=res['location']['region'].strip(),
|
region=res['location']['region'].strip(),
|
||||||
country=res['location']['country'],
|
country=res['location']['country'],
|
||||||
|
|
|
@ -40,7 +40,7 @@ class YouTube(Plugin):
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
return '\x02[YouTube]\x0F ' \
|
return '\x02[YouTube]\x02 ' \
|
||||||
'{title} - length {length} -\x033 {likes:,}\x03 /' \
|
'{title} - length {length} -\x033 {likes:,}\x03 /' \
|
||||||
'\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \
|
'\x034 {dislikes:,}\x03 ({score:,.1f}%) - {views:,} ' \
|
||||||
'views - {channel} on {date}' \
|
'views - {channel} on {date}' \
|
||||||
|
|
|
@ -20,10 +20,10 @@ def parse_int(val: str, select: bool = True) -> Tuple[int, str]:
|
||||||
val = int(val)
|
val = int(val)
|
||||||
if val is not 0:
|
if val is not 0:
|
||||||
if val < 1:
|
if val < 1:
|
||||||
order = 'desc'
|
order = 'DESC'
|
||||||
val *= -1
|
val *= -1
|
||||||
else:
|
else:
|
||||||
order = 'asc'
|
order = 'ASC'
|
||||||
if select:
|
if select:
|
||||||
val -= 1
|
val -= 1
|
||||||
return val, order
|
return val, order
|
||||||
|
|
Loading…
Reference in New Issue
Block a user