def __init__(self, models, settings, preset_roles): self.declared = False self.preset_roles = preset_roles self.commands_cache = [] self.addons = [] self.models = models self.WEBHOOK_URL_BASE = settings["url"] self.WEBHOOK_SSL_CERT = settings["cert"] self.TOKEN = settings["token"] self.bot = telebot.TeleBot(self.TOKEN, threaded=False) self.name = settings["name"] self.bot.parent_entity_name = self.name try: db_bot = models["Bots"].objects.get(name__exact=self.name) except models["Bots"].DoesNotExist: db_bot = models["Bots"](name=self.name) db_bot.is_active = False db_bot.description = settings["description"] db_bot.start_time = datetime.datetime.utcnow() myself = get_me(self.TOKEN) db_bot.telegram_id = myself["id"] db_bot.telegram_name = myself["username"] db_bot.save() self.db_bot = db_bot self.declare() self.all_bots.append(self)
def __init__(self, data, db=MongoClient()['marketbot']): super(MarketBot, self).__init__(data['token']) self.convos = {} self.db = db if not self.db.bots.update_one({'token': self.token}, {'$set': apihelper.get_me(self.token)}): self.db.bots.insert_one({'token': self.token}) self.email = data.get('email') self.last_update_id = data.get('last_update_id') or 0 self._init_bot() for convo_data in self.db.convos.find({'bot_token': self.token}): self.init_convo(convo_data)
def _bot_start(message): if message.chat.type == "group": admins = apihelper.get_chat_administrators(_config_.telegram_token, message.chat.id) for user in admins: if user['user']['id'] == apihelper.get_me( _config_.telegram_token)['id']: telegram_bot.send_message(message.chat.id, "Set unique id with /setid") break else: telegram_bot.send_message(message.chat.id, "Please promote me to admin") else: telegram_bot.send_message(message.chat.id, "Please add me to group")
def get_account_info(self) -> Dict[str, Any]: # data = { # 'id': 0123, # 'first_name': 'name', # 'last_name': 'name', # 'username': '******', # 'is_bot': True, # 'language_code': None # } try: data = apihelper.get_me(self.token) except Exception as err: raise MessengerException(err) return { 'id': data.get('id'), 'username': data.get('username'), 'uri': f'http://t.me/{data.get("username")}', 'info': data }
def get_me(self): result = apihelper.get_me(self.token) return types.User.de_json(result)
def get_me(self): result = apihelper.get_me(self.token) return types.User.de_json(json.dumps(result['result']))