diff --git a/README.md b/README.md index baf7230..5822cbe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# foBot -A simple bot for discord +# FoBot # + +FoBot is a simple discord bot created by non professional to practice programming skill. It is written in [Python](http://python.org "Python") and use the rewrited version of the lib [discord.py](https://github.com/Rapptz/discord.py/tree/rewrite "Discord.py-rewrite"). For the moment there isn't an official support server and the bot is not fully functional. + +## Configuration ## + +### For user who want an sms on error ### +You need to be a [free](https://free.fr "free") client. In the file `config_sms.py` you have to put your user id and your password. \ No newline at end of file diff --git a/SMSHandler.py b/SMSHandler.py new file mode 100644 index 0000000..e2bdde4 --- /dev/null +++ b/SMSHandler.py @@ -0,0 +1,9 @@ +import logging +import urllib + +import config_sms + +class SMSHandler(logging.Handler): + def emit(self, record): + msg = urllib.parse.quote(self.format(record).encode('utf8')) + urllib.request.urlopen("https://smsapi.free-mobile.fr/sendmsg?user=" + config_sms.user + "&pass=" + config_sms.password + "&msg=" + msg) \ No newline at end of file diff --git a/config_sms.py b/config_sms.py new file mode 100644 index 0000000..867c750 --- /dev/null +++ b/config_sms.py @@ -0,0 +1,2 @@ +user = "" +password = "" \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..cbb763d --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +import json +import logging +import logging.config +import os + +def setup_logging(default_path='log_config.json', default_level=logging.INFO, env_key='LOG_CFG', sms=True): + """Setup logging configuration + """ + path = default_path + value = os.getenv(env_key, None) + if value: + path = value + if os.path.exists(path): + with open(path, 'rt') as f: + config = json.load(f) + logging.config.dictConfig(config) + else: + logging.basicConfig(level=default_level) + + +setup_logging() + +log_discord = logging.getLogger('discord') +log_foBot = logging.getLogger('foBot') + +debug = log_foBot.debug +info = log_foBot.info +warning = log_foBot.warning +error = log_foBot.error +critical = log_foBot.critical