예제 #1
0
from SungJinwooRobot.versions import DB_STRUCTURE_VER


async def notify_bot_owner(old_ver, new_ver):
    await bot.send_message(
        OWNER_ID,
        f"Daisy database structure was updated from <code>{old_ver}</code> to <code>{new_ver}</code>",
    )


# TODO: Logs channel

log.debug("Checking on database structure update...")

if not (data := mongodb.db_structure.find_one({"db_ver": {"$exists": True}})):
    log.info("Your database is empty! Creating database structure key...")
    mongodb.db_structure.insert_one({"db_ver": DB_STRUCTURE_VER})
    log.info("Database structure version is: " + str(DB_STRUCTURE_VER))
else:
    curr_ver = data["db_ver"]
    log.info("Your database structure version is: " + str(curr_ver))
    if DB_STRUCTURE_VER > curr_ver:
        log.error("Your database is old! Waiting 20 seconds till update...")
        log.info("Press CTRL + C to cancel!")
        time.sleep(20)
        log.debug("Trying to update database structure...")
        log.info("--------------------------------")
        log.info("Your current database structure version: " + str(curr_ver))
        log.info("New database structure version: " + str(DB_STRUCTURE_VER))
        log.info("--------------------------------")
        old_ver = curr_ver
예제 #2
0
from SungJinwooRobot import BOT_USERNAME, dp
from SungJinwooRobot.config import get_bool_key
from SungJinwooRobot.modules.error import parse_update
from SungJinwooRobot.utils.filters import ALL_FILTERS
from SungJinwooRobot.utils.logger import log

DEBUG_MODE = get_bool_key("DEBUG_MODE")
ALLOW_F_COMMANDS = get_bool_key("ALLOW_FORWARDS_COMMANDS")
ALLOW_COMMANDS_FROM_EXC = get_bool_key("ALLOW_COMMANDS_WITH_!")
CMD_NOT_MONO = get_bool_key("DISALLOW_MONO_CMDS")

REGISTRED_COMMANDS = []
COMMANDS_ALIASES = {}

# Import filters
log.info("Filters to load: %s", str(ALL_FILTERS))
for module_name in ALL_FILTERS:
    log.debug("Importing " + module_name)
    imported_module = import_module("SungJinwooRobot.utils.filters." + module_name)
log.info("Filters loaded!")


def register(*args, cmds=None, f=None, allow_edited=True, allow_kwargs=False, **kwargs):
    if cmds and type(cmds) is str:
        cmds = [cmds]

    register_kwargs = {}

    if cmds and not f:
        regex = r"\A^{}(".format("[!/]" if ALLOW_COMMANDS_FROM_EXC else "/")
예제 #3
0
    'MONGODB_URI': 'localhost',
    'MONGO_DB': 'AllMight',

    'API_PORT': 8080,

    'JOIN_CONFIRM_DURATION': '30m',
}

CONF_PATH = 'data/bot_conf.yaml'
if os.name == 'nt':
    log.debug("Detected Windows, changing config path...")
    CONF_PATH = os.getcwd() + "\\data\\bot_conf.yaml"

if os.path.isfile(CONF_PATH):
    log.info(CONF_PATH)
    for item in (data := yaml.load(open('data/bot_conf.yaml', "r"), Loader=yaml.CLoader)):
        DEFAULTS[item.upper()] = data[item]
else:
    log.info("Using env vars")
    

def get_str_key(name, required=False):
    if name in DEFAULTS:
        default = DEFAULTS[name]
    else:
        default = None
    if not (data := env.str(name, default=default)) and not required:
        log.warning('No str key: ' + name)
        return None
    elif not data:
예제 #4
0
# 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 os
import signal

from SungJinwooRobot.services.redis import redis
from SungJinwooRobot.utils.logger import log


def exit_gracefully(signum, frame):
    log.warning("Bye!")

    try:
        redis.save()
    except Exception:
        log.error("Exiting immediately!")
    os.kill(os.getpid(), signal.SIGUSR1)


# Signal exit
log.info("Setting exit_gracefully task...")
signal.signal(signal.SIGINT, exit_gracefully)
예제 #5
0
# This file is part of Daisy (Telegram Bot)

# 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 sentry_sdk
from sentry_sdk.integrations.redis import RedisIntegration

from SungJinwooRobot.config import get_str_key
from SungJinwooRobot.utils.logger import log

log.info("Starting sentry.io integraion...")

sentry_sdk.init(get_str_key("SENTRY_API_KEY"), integrations=[RedisIntegration()])
예제 #6
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from apscheduler.executors.asyncio import AsyncIOExecutor
from apscheduler.jobstores.redis import RedisJobStore
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pytz import utc

from SungJinwooRobot.config import get_str_key
from SungJinwooRobot.utils.logger import log

DEFAULT = "default"

jobstores = {
    DEFAULT:
    RedisJobStore(
        host=get_str_key("REDIS_URI"),
        port=get_str_key("REDIS_PORT"),
        password=get_str_key("REDIS_PASS"),
    )
}
executors = {DEFAULT: AsyncIOExecutor()}
job_defaults = {"coalesce": False, "max_instances": 3}

scheduler = AsyncIOScheduler(jobstores=jobstores,
                             executors=executors,
                             job_defaults=job_defaults,
                             timezone=utc)

log.info("Starting apscheduller...")
scheduler.start()
예제 #7
0
# 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 os

import yaml
from babel.core import Locale

from SungJinwooRobot.services.mongo import db
from SungJinwooRobot.services.redis import redis
from SungJinwooRobot.utils.logger import log

LANGUAGES = {}

log.info("Loading localizations...")

for filename in os.listdir("SungJinwooRobot/localization"):
    log.debug("Loading language file " + filename)
    with open("SungJinwooRobot/localization/" + filename, "r",
              encoding="utf8") as f:
        lang = yaml.load(f, Loader=yaml.CLoader)

        lang_code = lang["language_info"]["code"]
        lang["language_info"]["babel"] = Locale(lang_code)

        LANGUAGES[lang_code] = lang

log.info("Languages loaded: {}".format([
    language["language_info"]["babel"].display_name
    for language in LANGUAGES.values()
예제 #8
0
async def channel_log(msg, info_log=True):
    chat_id = get_int_key("LOGS_CHANNEL_ID")
    if info_log:
        log.info(msg)

    await bot.send_message(chat_id, html.escape(msg, quote=False))