Skip to content

Commit e5d21a6

Browse files
committed
onload > on_start
1 parent 229354a commit e5d21a6

21 files changed

Lines changed: 48 additions & 45 deletions

cloudbot/hook.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,24 @@ def _sieve_hook(func):
277277
return lambda func: _sieve_hook(func)
278278

279279

280-
def onload(param=None, **kwargs):
281-
"""External onload decorator. Can be used directly as a decorator, or with args to return a decorator
280+
def on_start(param=None, **kwargs):
281+
"""External on_start decorator. Can be used directly as a decorator, or with args to return a decorator
282282
:type param: function | None
283283
"""
284284

285-
def _onload_hook(func):
286-
hook = _get_hook(func, "onload")
285+
def _on_start_hook(func):
286+
hook = _get_hook(func, "on_start")
287287
if hook is None:
288-
hook = _Hook(func, "onload")
288+
hook = _Hook(func, "on_start")
289289
_add_hook(func, hook)
290290

291291
hook._add_hook(kwargs)
292292
return func
293293

294294
if callable(param):
295-
return _onload_hook(param)
295+
return _on_start_hook(param)
296296
else:
297-
return lambda func: _onload_hook(func)
297+
return lambda func: _on_start_hook(func)
298+
299+
300+
onload = on_start

cloudbot/plugin.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def find_hooks(parent, module):
1818
"""
1919
:type parent: Plugin
2020
:type module: object
21-
:rtype: (list[CommandHook], list[RegexHook], list[RawHook], list[SieveHook], List[EventHook], list[OnloadHook])
21+
:rtype: (list[CommandHook], list[RegexHook], list[RawHook], list[SieveHook], List[EventHook], list[OnStartHook])
2222
"""
2323
# set the loaded flag
2424
module._cloudbot_loaded = True
@@ -27,8 +27,8 @@ def find_hooks(parent, module):
2727
raw = []
2828
sieve = []
2929
event = []
30-
onload = []
31-
type_lists = {"command": command, "regex": regex, "irc_raw": raw, "sieve": sieve, "event": event, "onload": onload}
30+
on_start = []
31+
type_lists = {"command": command, "regex": regex, "irc_raw": raw, "sieve": sieve, "event": event, "on_start": on_start}
3232
for name, func in module.__dict__.items():
3333
if hasattr(func, "_cloudbot_hook"):
3434
# if it has cloudbot hook
@@ -40,7 +40,7 @@ def find_hooks(parent, module):
4040
# delete the hook to free memory
4141
del func._cloudbot_hook
4242

43-
return command, regex, raw, sieve, event, onload
43+
return command, regex, raw, sieve, event, on_start
4444

4545

4646
def find_tables(code):
@@ -158,11 +158,11 @@ def load_plugin(self, path):
158158
# create database tables
159159
yield from plugin.create_tables(self.bot)
160160

161-
# run onload hooks
162-
for onload_hook in plugin.run_on_load:
163-
success = yield from self.launch(onload_hook, Event(bot=self.bot, hook=onload_hook))
161+
# run on_start hooks
162+
for on_start_hook in plugin.run_on_start:
163+
success = yield from self.launch(on_start_hook, Event(bot=self.bot, hook=on_start_hook))
164164
if not success:
165-
logger.warning("Not registering hooks from plugin {}: onload hook errored".format(plugin.title))
165+
logger.warning("Not registering hooks from plugin {}: on_start hook errored".format(plugin.title))
166166

167167
# unregister databases
168168
plugin.unregister_tables(self.bot)
@@ -214,7 +214,7 @@ def load_plugin(self, path):
214214
self._log_hook(sieve_hook)
215215

216216
# we don't need this anymore
217-
del plugin.run_on_load
217+
del plugin.run_on_start
218218

219219
@asyncio.coroutine
220220
def unload_plugin(self, path):
@@ -408,7 +408,7 @@ def launch(self, hook, event):
408408
:type hook: cloudbot.plugin.Hook | cloudbot.plugin.CommandHook
409409
:rtype: bool
410410
"""
411-
if hook.type != "onload": # we don't need sieves on onload hooks.
411+
if hook.type != "on_start": # we don't need sieves on on_start hooks.
412412
for sieve in self.bot.plugin_manager.sieves:
413413
event = yield from self._sieve(sieve, event, hook)
414414
if event is None:
@@ -483,7 +483,7 @@ def __init__(self, filepath, filename, title, code):
483483
self.file_path = filepath
484484
self.file_name = filename
485485
self.title = title
486-
self.commands, self.regexes, self.raw_hooks, self.sieves, self.events, self.run_on_load = find_hooks(self, code)
486+
self.commands, self.regexes, self.raw_hooks, self.sieves, self.events, self.run_on_start = find_hooks(self, code)
487487
# we need to find tables for each plugin so that they can be unloaded from the global metadata when the
488488
# plugin is reloaded
489489
self.tables = find_tables(code)
@@ -686,19 +686,19 @@ def __str__(self):
686686
self.plugin.file_name)
687687

688688

689-
class OnloadHook(Hook):
690-
def __init__(self, plugin, on_load_hook):
689+
class OnStartHook(Hook):
690+
def __init__(self, plugin, on_start_hook):
691691
"""
692692
:type plugin: Plugin
693-
:type on_load_hook: cloudbot.util.hook._OnLoadHook
693+
:type on_start_hook: cloudbot.util.hook._On_startHook
694694
"""
695-
super().__init__("onload", plugin, on_load_hook)
695+
super().__init__("on_start", plugin, on_start_hook)
696696

697697
def __repr__(self):
698-
return "Onload[{}]".format(Hook.__repr__(self))
698+
return "On_start[{}]".format(Hook.__repr__(self))
699699

700700
def __str__(self):
701-
return "onload {} from {}".format(self.function_name, self.plugin.file_name)
701+
return "on_start {} from {}".format(self.function_name, self.plugin.file_name)
702702

703703

704704
_hook_name_to_plugin = {
@@ -707,5 +707,5 @@ def __str__(self):
707707
"irc_raw": RawHook,
708708
"sieve": SieveHook,
709709
"event": EventHook,
710-
"onload": OnloadHook
710+
"on_start": OnStartHook
711711
}

plugins/attacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from cloudbot.util import textgen
1010

1111

12-
@hook.onload()
12+
@hook.on_start()
1313
def load_attacks(bot):
1414
"""
1515
:type bot: cloudbot.bot.CloudBot

plugins/eightball.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from cloudbot.util import colors
88

99

10-
@hook.onload()
10+
@hook.on_start()
1111
def load_responses(bot):
1212
path = os.path.join(bot.data_dir, "8ball_responses.txt")
1313
global responses

plugins/encrypt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def decode_aes(c, s):
4444
return "Invalid password for the given message (couldn't encode result as utf-8)"
4545

4646

47-
@hook.onload
47+
@hook.on_start
4848
def create_db(db):
4949
"""check to see that our db has the the encryption table.
5050
:type db: sqlalchemy.orm.session.Session

plugins/factoids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _load_cache_db(db):
2828

2929

3030
@asyncio.coroutine
31-
@hook.onload()
31+
@hook.on_start()
3232
def load_cache(async, db):
3333
"""
3434
:type db: sqlalchemy.orm.Session

plugins/fortune.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from cloudbot import hook
77

88

9-
@hook.onload()
9+
@hook.on_start()
1010
def load_fortunes(bot):
1111
path = os.path.join(bot.data_dir, "fortunes.txt")
1212
global fortunes

plugins/geoip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def check_db(loop):
7272

7373

7474
@asyncio.coroutine
75-
@hook.onload
75+
@hook.on_start
7676
def load_geoip(loop):
7777
asyncio.async(check_db(loop), loop=loop)
7878

plugins/horoscope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from cloudbot.util import formatting
88

99

10-
@hook.onload()
10+
@hook.on_start()
1111
def init(db):
1212
db.execute("create table if not exists horoscope(nick primary key, sign)")
1313
db.commit()

plugins/ignore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
@hook.onload
22+
@hook.on_start
2323
def load_cache(db):
2424
"""
2525
:type db: sqlalchemy.orm.Session

0 commit comments

Comments
 (0)