Moved @irc3.plugin into bot.plugins.BasePlugin -> saved some lines

This commit is contained in:
mrhanky 2017-08-22 16:47:10 +02:00
parent 1939635cdb
commit 7f5571fc09
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8
18 changed files with 30 additions and 47 deletions

4
bot/__init__.py Normal file
View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
import os
REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View File

@ -1,12 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from irc3 import IrcBot import irc3
from irc3.plugins.command import Commands from irc3.plugins.command import Commands
MODULE = __name__ MODULE = __name__
@irc3.plugin
class BasePlugin(object): class BasePlugin(object):
def __init__(self, bot: IrcBot): def __init__(self, bot: irc3.IrcBot):
self.bot = bot self.bot = bot
self.log = bot.log self.log = bot.log
self.guard = bot.get_plugin(Commands).guard self.guard = bot.get_plugin(Commands).guard
@ -23,7 +24,7 @@ from .storage import Storage # noqa
class DatabasePlugin(Plugin): class DatabasePlugin(Plugin):
def __init__(self, bot: IrcBot): def __init__(self, bot: irc3.IrcBot):
super().__init__(bot) super().__init__(bot)
# Get PgSQL storage instance and connection + cursor # Get PgSQL storage instance and connection + cursor
self.db = bot.get_plugin(Storage) self.db = bot.get_plugin(Storage)

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import irc3
import requests import requests
from docopt import Dict from docopt import Dict
from irc3.plugins.command import command from irc3.plugins.command import command
@ -8,7 +7,6 @@ from irc3.utils import IrcString
from . import Plugin from . import Plugin
@irc3.plugin
class Coins(Plugin): class Coins(Plugin):
requires = ['irc3.plugins.command'] requires = ['irc3.plugins.command']

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time import time
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
@ -9,7 +8,6 @@ from irc3.utils import IrcString
from . import Plugin from . import Plugin
@irc3.plugin
class CTCP(Plugin): class CTCP(Plugin):
requires = ['irc3.plugins.async', requires = ['irc3.plugins.async',
'irc3.plugins.command'] 'irc3.plugins.command']

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from urllib.parse import urlparse from urllib.parse import urlparse
import irc3
import requests import requests
from docopt import Dict from docopt import Dict
from irc3.plugins.command import command from irc3.plugins.command import command
@ -10,7 +9,6 @@ from irc3.utils import IrcString
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Useless(DatabasePlugin): class Useless(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
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
@ -10,7 +9,6 @@ from . import DatabasePlugin
from ..utils import parse_int from ..utils import parse_int
@irc3.plugin
class McManiac(DatabasePlugin): class McManiac(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re import re
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
@ -11,7 +10,6 @@ from . import DatabasePlugin
from ..utils import parse_int from ..utils import parse_int
@irc3.plugin
class Quotes(DatabasePlugin): class Quotes(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import random import random
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
@ -9,7 +8,6 @@ from irc3.utils import IrcString
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Rape(DatabasePlugin): class Rape(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -7,7 +7,6 @@ from irc3.utils import IrcString
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Useless(DatabasePlugin): class Useless(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -9,7 +9,6 @@ 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',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -8,7 +8,6 @@ from psycopg2.extras import DictCursor
from . import Plugin from . import Plugin
@irc3.plugin
class Storage(Plugin): class Storage(Plugin):
def __init__(self, bot: irc3.IrcBot): def __init__(self, bot: irc3.IrcBot):
super().__init__(bot) super().__init__(bot)

View File

@ -10,7 +10,6 @@ from psycopg2 import Error
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Tell(DatabasePlugin): class Tell(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -14,7 +14,6 @@ from psycopg2.extras import DictRow
from . import DatabasePlugin from . import DatabasePlugin
@irc3.plugin
class Timer(DatabasePlugin): class Timer(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import irc3
import requests import requests
from docopt import Dict from docopt import Dict
from irc3.plugins.command import command from irc3.plugins.command import command
@ -8,7 +7,6 @@ from irc3.utils import IrcString
from . import Plugin from . import Plugin
@irc3.plugin
class Urban(Plugin): class Urban(Plugin):
requires = ['irc3.plugins.command'] requires = ['irc3.plugins.command']

View File

@ -11,29 +11,13 @@ from psycopg2 import Error
from . import DatabasePlugin from . import DatabasePlugin
from ..utils import re_generator from ..utils import re_generator
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
RAINBOW_LEN = len(RAINBOW)
ISPS = (
't-ipconnect',
'telefonica',
'vodafone',
'kabel',
'unity-media',
)
GENDERS = (
'male',
'female',
'shemale',
'hermaphrodite',
)
@irc3.plugin
class Useless(DatabasePlugin): class Useless(DatabasePlugin):
requires = ['irc3.plugins.command', requires = ['irc3.plugins.command',
'bot.plugins.storage'] 'bot.plugins.storage']
RAINBOW = (5, 7, 8, 9, 3, 10, 12, 2, 6, 13)
WOAH = ( WOAH = (
'woah', 'woah',
'woah indeed', 'woah indeed',
@ -41,6 +25,21 @@ class Useless(DatabasePlugin):
'keep your woahs to yourself', 'keep your woahs to yourself',
) )
ISPS = (
't-ipconnect',
'telefonica',
'vodafone',
'kabel',
'unity-media',
)
GENDERS = (
'male',
'female',
'shemale',
'hermaphrodite',
)
@command(permission='admin', show_in_help=False) @command(permission='admin', show_in_help=False)
def kim(self, mask: IrcString, target: IrcString, args: Dict): def kim(self, mask: IrcString, target: IrcString, args: Dict):
"""Kicks Kim, most useful command. """Kicks Kim, most useful command.
@ -49,7 +48,7 @@ class Useless(DatabasePlugin):
""" """
self.bot.kick(target, 'Kim') self.bot.kick(target, 'Kim')
@irc3.event(r'(?i)^:(?P<mask>\S+@\S+({isps})\S+) JOIN :(?P<target>#\S+)$'.format(isps='|'.join(ISPS))) @irc3.event(r'(?i)^:(?P<mask>\S+@\S+({})\S+) JOIN :(?P<target>#\S+)$'.format('|'.join(ISPS)))
def bounce(self, mask, target): def bounce(self, mask, target):
nick = IrcString(mask).nick nick = IrcString(mask).nick
@ -286,7 +285,7 @@ class Useless(DatabasePlugin):
%%assume [<nick>] %%assume [<nick>]
""" """
nick = args.get('<nick>', mask.nick) nick = args.get('<nick>', mask.nick)
gender = random.choice(GENDERS) gender = random.choice(self.GENDERS)
return 'Assuming {}\'s gender... they\'re a {}.'.format(nick, gender) return 'Assuming {}\'s gender... they\'re a {}.'.format(nick, gender)
@ -338,4 +337,4 @@ class Useless(DatabasePlugin):
# noinspection PyMethodMayBeStatic # noinspection PyMethodMayBeStatic
def _rainbow(self, i, char): def _rainbow(self, i, char):
return '\x03{0:02d}{1}'.format(RAINBOW[i % RAINBOW_LEN], char) return '\x03{0:02d}{1}'.format(self.RAINBOW[i % len(self.RAINBOW)], char)

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import irc3
import requests import requests
from docopt import Dict from docopt import Dict
from irc3.plugins.command import command from irc3.plugins.command import command
@ -8,7 +7,6 @@ from irc3.utils import IrcString
from . import Plugin from . import Plugin
@irc3.plugin
class Weather(Plugin): class Weather(Plugin):
requires = ['irc3.plugins.command'] requires = ['irc3.plugins.command']

View File

@ -12,7 +12,6 @@ from . import Plugin
from ..utils import date_from_iso from ..utils import date_from_iso
@irc3.plugin
class YouTube(Plugin): class YouTube(Plugin):
requires = ['irc3.plugins.command'] requires = ['irc3.plugins.command']

View File

@ -4,5 +4,6 @@ git+https://github.com/mrhanky17/docopt.git#egg=docopt
aiocron==0.6 aiocron==0.6
psycopg2==2.7.1 psycopg2==2.7.1
requests==2.14.2 requests==2.14.2
GitPython==2.1.5
feedparser==5.2.1 feedparser==5.2.1
python_dotenv==0.6.4 python_dotenv==0.6.4