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