-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/faeture/xp-improvements' into po…
…kemon_optimizer
- Loading branch information
Showing
12 changed files
with
167 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
import logging | ||
import time | ||
|
||
|
||
class BaseTask(object): | ||
TASK_API_VERSION = 1 | ||
|
||
def __init__(self, bot, config): | ||
self.bot = bot | ||
self.config = config | ||
self._validate_work_exists() | ||
self.logger = logging.getLogger(type(self).__name__) | ||
self.initialize() | ||
|
||
def _validate_work_exists(self): | ||
method = getattr(self, 'work', None) | ||
if not method or not callable(method): | ||
raise NotImplementedError('Missing "work" method') | ||
|
||
def emit_event(self, event, sender=None, level='info', formatted='', data={}): | ||
if not sender: | ||
sender=self | ||
self.bot.event_manager.emit( | ||
event, | ||
sender=sender, | ||
level=level, | ||
formatted=formatted, | ||
data=data | ||
) | ||
|
||
def initialize(self): | ||
pass | ||
TASK_API_VERSION = 1 | ||
|
||
def __init__(self, bot, config): | ||
self.bot = bot | ||
self.config = config | ||
self._validate_work_exists() | ||
self.logger = logging.getLogger(type(self).__name__) | ||
self.last_ran = time.time() | ||
self.run_interval = config.get('run_interval', 10) | ||
self.initialize() | ||
|
||
def _update_last_ran(self): | ||
self.last_ran = time.time() | ||
|
||
def _time_to_run(self): | ||
interval = time.time() - self.last_ran | ||
if interval > self.run_interval: | ||
return True | ||
return False | ||
|
||
def _validate_work_exists(self): | ||
method = getattr(self, 'work', None) | ||
if not method or not callable(method): | ||
raise NotImplementedError('Missing "work" method') | ||
|
||
def emit_event(self, event, sender=None, level='info', formatted='', data={}): | ||
if not sender: | ||
sender=self | ||
self.bot.event_manager.emit( | ||
event, | ||
sender=sender, | ||
level=level, | ||
formatted=formatted, | ||
data=data | ||
) | ||
|
||
def initialize(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.