Huge cleanup and refactoring :>
This commit is contained in:
96
bot/admin.py
Normal file
96
bot/admin.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
|
||||
import irc3
|
||||
from git import Repo
|
||||
from docopt import Dict
|
||||
from irc3.plugins.command import command
|
||||
from irc3.utils import IrcString
|
||||
|
||||
from . import MODULE, Bot, Plugin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@command(permission='admin', show_in_help_list=False)
|
||||
def reload(bot: Bot, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Reloads a plugin or the whole bot.
|
||||
|
||||
%%reload [<plugin>]
|
||||
"""
|
||||
plugin = args.get('<plugin>')
|
||||
if plugin:
|
||||
bot.reload('{}.{}'.format(MODULE, plugin))
|
||||
bot.privmsg(target, 'Reloaded plugin "{}"'.format(plugin))
|
||||
else:
|
||||
bot.reload()
|
||||
bot.privmsg(target, 'Reloaded the bot')
|
||||
|
||||
|
||||
@irc3.event(irc3.rfc.CONNECTED)
|
||||
def connected(bot, srv, me, data):
|
||||
bot.mode(me, '+R')
|
||||
|
||||
|
||||
class Admin(Plugin):
|
||||
def __init__(self, bot: Bot):
|
||||
super().__init__(bot)
|
||||
self.repo = Repo(self.bot.REPO_DIR)
|
||||
|
||||
@command(permission='all_permissions')
|
||||
def pull(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Pull from the git repo
|
||||
|
||||
%%pull [<origin>]
|
||||
"""
|
||||
origin = args.get('<origin>', 'origin')
|
||||
|
||||
try:
|
||||
self.repo.remote(origin).pull()
|
||||
except ValueError as ex:
|
||||
return '[GIT] {}'.format(ex)
|
||||
|
||||
self.bot.reload()
|
||||
return '[GIT] Pulled from {} and reloaded the bot'.format(origin)
|
||||
|
||||
@command(permission='all_permissions')
|
||||
def nick(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Change the nick of the bot (not permanent)
|
||||
|
||||
%%nick <nick>
|
||||
"""
|
||||
self.bot.nick = args['<nick>']
|
||||
|
||||
@command(permission='all_permissions')
|
||||
def join(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Let the bot join a channel
|
||||
|
||||
%%join <channel>
|
||||
"""
|
||||
channel = args.get('<channel>', target)
|
||||
|
||||
self.bot.join(channel)
|
||||
self.bot.notice(mask.nick, 'Joined channel {}'.format(channel))
|
||||
|
||||
@command(permission='all_permissions')
|
||||
def part(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Let the bot part a given or the current channel
|
||||
|
||||
%%part [<channel>]
|
||||
"""
|
||||
channel = args.get('<channel>', target)
|
||||
|
||||
self.bot.join(channel)
|
||||
self.bot.notice(mask.nick, 'Parted channel {}'.format(channel))
|
||||
|
||||
@command(permission='all_permissions')
|
||||
def cycle(self, mask: IrcString, target: IrcString, args: Dict):
|
||||
"""Let the bot part and join a given or the current channel
|
||||
|
||||
%%cycle [<channel>]
|
||||
"""
|
||||
channel = args.get('<channel>', target)
|
||||
|
||||
self.bot.part(channel)
|
||||
self.bot.join(channel)
|
||||
self.bot.notice(mask.nick, 'Cycled channel {}'.format(channel))
|
||||
Reference in New Issue
Block a user