Added admin functions (atm non-persistent
This commit is contained in:
parent
4fa23eacc9
commit
1939635cdb
|
@ -2,11 +2,13 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import irc3
|
import irc3
|
||||||
|
from git import Repo
|
||||||
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 . import MODULE, Plugin
|
from . import MODULE, Plugin
|
||||||
|
from .. import REPO_DIR
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -31,7 +33,63 @@ def connected(bot, srv, me, data):
|
||||||
bot.mode(me, '+R')
|
bot.mode(me, '+R')
|
||||||
|
|
||||||
|
|
||||||
@irc3.plugin
|
|
||||||
class Admin(Plugin):
|
class Admin(Plugin):
|
||||||
# TODO: add admin functions (join, part, etc)
|
def __init__(self, bot: irc3.IrcBot):
|
||||||
pass
|
super().__init__(bot)
|
||||||
|
self.repo = Repo(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>
|
||||||
|
"""
|
||||||
|
self.join_part('join', mask, target, args)
|
||||||
|
|
||||||
|
@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>]
|
||||||
|
"""
|
||||||
|
self.join_part('part', mask, target, args)
|
||||||
|
|
||||||
|
@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>]
|
||||||
|
"""
|
||||||
|
self.join_part('part', mask, target, args)
|
||||||
|
self.join_part('join', mask, target, args)
|
||||||
|
|
||||||
|
def join_part(self, func: str, mask: IrcString, target: IrcString, args: Dict):
|
||||||
|
channel = IrcString(args.get('<channel>') or target)
|
||||||
|
|
||||||
|
if channel.is_channel:
|
||||||
|
getattr(self.bot, func)(channel)
|
||||||
|
self.bot.notice(mask.nick, '{}ed channel {}'.format(func, channel))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user