diff --git a/mods/autoload.py b/mods/autoload.py new file mode 100644 index 0000000..d5b9259 --- /dev/null +++ b/mods/autoload.py @@ -0,0 +1,28 @@ +# This file is part of modbot. + +# modbot is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public +# License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any +# later version. + +# modbot is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero +# General Public License along with modbot. If not, see +# . + +# configuration +to_load = [ + 'ducks', +] + +def init(srv): + for i in to_load: + try: + srv.load_mod(i) + except ModuleNotFoundError: + pass diff --git a/mods/default.py b/mods/default.py index e2c74fd..5f30528 100644 --- a/mods/default.py +++ b/mods/default.py @@ -20,7 +20,7 @@ import utils def cmd(line, srv): command, params = utils.cmdparse(line) if command == "load": - if utils.is_admin(params[0]): + if utils.is_admin(srv, params[0]): try: srv.load_mod(params[0]) utils.message(srv, line.params[0], @@ -32,7 +32,7 @@ def cmd(line, srv): utils.message(srv, line.params[0], "invalid permissions!") elif command == "unload": - if utils.is_admin(params[0]): + if utils.is_admin(srv, params[0]): try: srv.unload_mod(params[0]) utils.message(srv, line.params[0], @@ -44,7 +44,7 @@ def cmd(line, srv): utils.message(srv, line.params[0], "invalid permissions!") elif command == "op": - if utils.is_admin(params[0]): + if utils.is_admin(srv, params[0]): srv.admins.append(Admin(params[0])) utils.message(srv, line.params[0], "operator added") diff --git a/mods/ducks.py b/mods/ducks.py new file mode 100644 index 0000000..2928b5d --- /dev/null +++ b/mods/ducks.py @@ -0,0 +1,46 @@ +# This file is part of modbot. + +# modbot is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public +# License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any +# later version. + +# modbot is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty +# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero +# General Public License along with modbot. If not, see +# . + +import utils +from irctokens import build, Line +import time +import random + +def init(srv): + srv.states['ducks'] = { + 'messages': 0, + 'duck': False, + 'last': time.time(), + } + +def privmsg(line, srv): + if srv.states['ducks'] == None: + init(srv) + if not line.hostmask.nickname == "BitBotNewTest": srv.states['ducks']['messages'] += 1 + if random.randint(0, 99) <= 76 and srv.states['ducks']['messages'] > 1 and not srv.states['ducks']['duck']: + srv.states['ducks']['duck'] = True + srv.send(build('PRIVMSG', [line.params[0], 'a duck has appeared!'])) + srv.states['ducks']['messages'] = 0 + +def cmd(line, srv): + command, params = utils.cmdparse(line) + if command == "bef": + if srv.states['ducks']['duck']: + utils.message(srv, line.params[0], "you cought a duck!") + srv.states['ducks']['duck'] = False + else: + utils.message(srv, line.params[0], "oh noes, you didn't catch it!")