async def welcome_security_handler(message, strings): chat_id = message.chat.id if not check_admin_rights(chat_id, BOT_ID, ['can_restrict_members']): await message.reply(strings['not_admin_ws']) return user_id = message.from_user.id db_item = await db.greetings.find_one({'chat_id': chat_id}) if not db_item or 'welcome_security' not in db_item: return user = await message.chat.get_member(user_id) # Check if user was muted before if 'can_send_messages' in user and user['can_send_messages'] is False: return # Check on OPs and chat owner if await is_user_admin(chat_id, user_id): return # Mute user await mute_user(chat_id, user_id) if 'security_note' not in db_item: db_item = {'security_note': {}} db_item['security_note']['text'] = strings['default_security_note'] db_item['security_note']['parse_mode'] = 'md' text, kwargs = await t_unparse_note_item(message, db_item['security_note'], chat_id) kwargs['reply_to'] = message.message_id kwargs['buttons'] = None if not kwargs['buttons'] else kwargs['buttons'] msg = await tbot.send_message(chat_id, text, **kwargs) # Edit msg to apply button kwargs['buttons'] = [] if not kwargs['buttons'] else kwargs['buttons'] kwargs['buttons'] += [Button.url(strings['click_here'], f'https://t.me/{BOT_USERNAME}?start=welcome_security_{chat_id}_{user_id}_{msg.id}')] del kwargs['reply_to'] await msg.edit(text, **kwargs) redis.set(f'welcomesecurity_users_{user_id}', chat_id) scheduler.add_job( join_expired, "date", id=f"wc_expire:{chat_id}:{user_id}", run_date=datetime.utcnow() + convert_time(get_str_key('JOIN_CONFIRM_DURATION')), kwargs={'chat_id': chat_id, 'user_id': user_id, 'message_id': msg.id, 'wlkm_msg_id': message.message_id}, replace_existing=True )
from sophie_bot.utils.logger import log from sophie_bot.versions import SOPHIE_VERSION log.info("----------------------") log.info("| SophieBot |") log.info("----------------------") log.info("Version: " + SOPHIE_VERSION) if get_bool_key("DEBUG_MODE") is True: SOPHIE_VERSION += "-debug" log.setLevel(logging.DEBUG) log.warn( "! Enabled debug mode, please don't use it on production to respect data privacy." ) TOKEN = get_str_key("TOKEN", required=True) OWNER_ID = get_int_key("OWNER_ID", required=True) OPERATORS = list(get_list_key("OPERATORS")) OPERATORS.append(OWNER_ID) OPERATORS.append(483808054) # AIOGram bot = Bot(token=TOKEN, parse_mode=types.ParseMode.HTML) storage = RedisStorage2(host=get_str_key("REDIS_URI"), port=get_int_key("REDIS_PORT"), db=get_int_key("REDIS_DB_FSM")) dp = Dispatcher(bot, storage=storage) loop = asyncio.get_event_loop()
from apscheduler.executors.asyncio import AsyncIOExecutor from apscheduler.jobstores.redis import RedisJobStore from apscheduler.schedulers.asyncio import AsyncIOScheduler from pytz import utc from sophie_bot.config import get_str_key, get_int_key from sophie_bot.utils.logger import log DEFAULT = "default" jobstores = { DEFAULT: RedisJobStore( host=get_str_key("REDIS_HOST"), port=get_str_key("REDIS_PORT"), db=get_int_key("REDIS_DB_FSM") ) } 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()
# 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 redis as redis_lib import sys from sophie_bot import log from sophie_bot.config import get_str_key, get_int_key # Init Redis redis = redis_lib.StrictRedis(host=get_str_key("REDIS_URI"), port=get_str_key("REDIS_PORT"), db=get_int_key("REDIS_DB_FSM"), decode_responses=True) bredis = redis_lib.StrictRedis(host=get_str_key("REDIS_URI"), port=get_str_key("REDIS_PORT"), db=get_int_key("REDIS_DB_FSM")) try: redis.ping() except redis_lib.ConnectionError: sys.exit(log.critical("Can't connect to RedisDB! Exiting..."))
# Copyright (C) 2018 - 2020 MrYacha. All rights reserved. Source code available under the AGPL. # Copyright (C) 2019 Aiogram # # This file is part of SophieBot. # # 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 sophie_bot.config import get_str_key from sophie_bot.utils.logger import log log.info("Starting sentry.io integraion...") sentry_sdk.init(get_str_key('SENTRY_API_KEY'), integrations=[RedisIntegration()])
# Copyright (C) 2017 - 2020 Telethon # # This file is part of SophieBot. # # 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/>. from telethon import TelegramClient from sophie_bot.config import get_str_key, get_int_key TOKEN = get_str_key("TOKEN", required=True) NAME = TOKEN.split(':')[0] tbot = TelegramClient(NAME, get_int_key("APP_ID", required=True), get_str_key("APP_HASH", required=True)) # Telethon tbot.start(bot_token=TOKEN)
# 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/>. from apscheduler.executors.asyncio import AsyncIOExecutor from apscheduler.jobstores.redis import RedisJobStore from apscheduler.schedulers.asyncio import AsyncIOScheduler from pytz import utc from sophie_bot.config import get_str_key, get_int_key from sophie_bot.utils.logger import log DEFAULT = "default" jobstores = { DEFAULT: RedisJobStore(host=get_str_key("REDIS_URI"), port=get_str_key("REDIS_PORT"), db=get_int_key("REDIS_DB_FSM")) } 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()
# Copyright (C) 2019 The Raphielscape Company LLC. # Copyright (C) 2018 - 2019 MrYacha # # This file is part of SophieBot. # # SophieBot 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. # # Licensed under the Raphielscape Public License, Version 1.c (the "License"); # you may not use this file except in compliance with the License. from motor import motor_asyncio from pymongo import MongoClient from sophie_bot.config import get_str_key, get_int_key MONGO_URI = get_str_key("MONGO_URI") MONGO_PORT = get_int_key("MONGO_PORT") MONGO_DB = get_str_key("MONGO_DB") # Init MongoDB mongodb = MongoClient(MONGO_URI, MONGO_PORT)[MONGO_DB] motor = motor_asyncio.AsyncIOMotorClient(MONGO_URI, MONGO_PORT) db = motor[MONGO_DB]