nemubot/nemubot/bot.py

48 lines
1.4 KiB
Python
Raw Normal View History

2015-02-21 12:51:40 +00:00
# Nemubot is a smart and modulable IM bot.
2016-01-31 19:45:44 +00:00
# Copyright (C) 2012-2016 Mercier Pierre-Olivier
2015-02-21 12:51:40 +00:00
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
import logging
2015-10-08 22:24:44 +00:00
import sys
2015-02-21 12:51:40 +00:00
2016-11-10 17:39:52 +00:00
class Bot:
2015-02-21 12:51:40 +00:00
"""Class containing the bot context and ensuring key goals"""
2016-11-10 17:39:52 +00:00
logger = logging.getLogger("nemubot")
2015-02-21 12:51:40 +00:00
2016-11-10 17:39:52 +00:00
def __init__(self):
"""Initialize the bot context
2015-02-21 12:51:40 +00:00
"""
2016-11-10 17:39:52 +00:00
from nemubot import __version__
Bot.logger.info("Initiate nemubot v%s, running on Python %s",
__version__, sys.version.split("\n")[0])
2015-02-21 12:51:40 +00:00
2016-11-10 17:39:52 +00:00
import asyncio
self._loop = asyncio.get_event_loop()
2015-02-21 12:51:40 +00:00
def run(self):
2016-11-10 17:39:52 +00:00
self._loop.run_forever()
self._loop.close()
2015-02-21 12:51:40 +00:00
2016-11-10 17:39:52 +00:00
def stop(self):
2015-02-21 12:51:40 +00:00
"""Save and unload modules and disconnect servers"""
2016-11-10 17:39:52 +00:00
self._loop.stop()