def company(update, _): #update.message.reply_text(update.message.text) #message_text = update.message.text chat_id = update.message.chat_id user_id = update.message.chat.id uid = str(user_id) nickname = update.message.from_user.username user = User(nickname, uid) reg = backend.search(user.userid) if reg: send_new_problem(user_id, chat_id) return if not user.register(bot, chat_id, update): reply = 'Unable to create an account!' bot.send_message(chat_id=chat_id, text=reply) return logger.info(f'User {nickname}({uid}) registered') ENTITY[uid] = user bot.send_message(chat_id=chat_id, text=reply_msg('welcome')) send_new_problem(user_id, chat_id)
def init_config(self, config): """ Function that loads the configuration file. :param config: the configuration file :return: None """ # TOOD(xevi): why Persian here? self.rtl_languages = ['fa'] # setup the database info from configobj import ConfigObj if config and isinstance(config, ConfigObj): self.user = User( config.get('host', ''), config.get('database', ''), config.get('user', ''), config.get('password', '')) else: raise OSMError('No config file: ' \ 'Please provide a ConfigObj object instance.') # setup the jinja environment and default language # TODO(xevi): Should we set a default language? self.jinja_env = Environment(extensions=['jinja2.ext.i18n']) self.jinja_env.filters['url_escape'] = url_escape self.jinja_env.filters['escape_underscoere'] = escape_underscoere self.language = None # setup the telegram API. Before check token existence token = config.get('token', '') if token: self.telegram_api = telegram.Bot(token) else: raise OSMError('No token in config file: ' \ 'Please check that token is in the config file.')
def start_cmd(update, context): """Bot start command""" user = update.effective_user # If user is here for the first time > Save him to the DB u = User(user_id=user.id, first_name=user.first_name, last_name=user.last_name, username=user.username, lang_code=user.language_code) core.add_user_if_new(u) context.bot.sendMessage(user.id, MainMenu.text, reply_markup=MainMenu.keyboard) context.user_data["state"] = State.IDLE
def start_handler(update, _): global ENTITY chat_id = update.message.chat_id uid = str(chat_id) nickname = update.message.from_user.first_name if uid in ENTITY: send_new_problem(chat_id) else: user = User(uid, nickname) if not user.register(): reply = '無法建立帳號,請於粉專或 discord 私訊小編!' bot.send_message(chat_id=chat_id, text=reply) return logger.info(f'User {nickname}({uid}) registered') ENTITY[uid] = user bot.send_message(chat_id=chat_id, text=reply_msg('welcome')) send_new_problem(chat_id)
def add_entity(update, context): msg = update.message text = update.message.text t_user = update.effective_user logger.info("Adding new entity for user '{}'".format(t_user.id)) reply_markup = InlineKeyboardMarkup([[cancel_button]]) user = User(user_id=t_user.id, first_name=t_user.first_name, last_name=t_user.last_name, username=t_user.username, lang_code=t_user.language_code) core.add_user_if_new(user) try: entity_type = core.get_type_by_url(text) url = core.get_e_url(text, entity_type) logger.info("Valid URL for new entity is '{}'".format(url)) except InvalidURLException: logger.warning("Invalid url '{}' sent by user {}!".format(text, t_user)) msg.reply_text(text="Die URL ist ungültig!", reply_markup=reply_markup) return try: if entity_type == EntityType.WISHLIST: entity = Wishlist.from_url(url) elif entity_type == EntityType.PRODUCT: entity = Product.from_url(url) else: raise ValueError("EntityType '{}' not found!".format(entity_type)) except HTTPError as e: logger.error(e) if e.response.status_code == 403: msg.reply_text(text="Die URL ist nicht öffentlich einsehbar, daher wurde kein neuer Preisagent erstellt!") elif e.response.status_code == 429: msg.reply_text(text="Entschuldige, ich bin temporär bei Geizhals blockiert und kann keine Preise auslesen. Bitte probiere es später noch einmal.") except (ValueError, Exception) as e: # Raised when price could not be parsed logger.error(e) msg.reply_text(text="Name oder Preis konnte nicht ausgelesen werden! Preisagent wurde nicht erstellt!") else: core.add_entity_if_new(entity) try: logger.debug("Subscribing to entity.") core.subscribe_entity(user, entity) entity_data = EntityType.get_type_article_name(entity_type) msg.reply_html("Preisagent für {article} {type} {link_name} erstellt! Aktueller Preis: {price}".format( article=entity_data.get("article"), type=entity_data.get("name"), link_name=link(entity.url, entity.name), price=bold(price(entity.price, signed=False))), disable_web_page_preview=True) context.user_data["state"] = State.IDLE except AlreadySubscribedException: logger.debug("User already subscribed!") msg.reply_text("Du hast bereits einen Preisagenten für diese URL! Bitte sende mir eine andere URL.", reply_markup=InlineKeyboardMarkup([[cancel_button]]))
def get_user(self, user_id): self.cursor.execute( "SELECT user_id, first_name, username, lang_code FROM users WHERE user_id=?;", [str(user_id)]) user_data = self.cursor.fetchone() if user_data: return User(user_id=user_data[0], first_name=user_data[1], username=user_data[2], lang_code=user_data[3]) return None
def __onMessage(self, bot, update): try: user = User.fromMessage(update.message) responses = self.dispatcher.process(user, update.message.text) for response in responses: bot.send_message(chat_id=response.chatId, parse_mode=response.parseMode, text=response.msg) except Exception as e: print(e) traceback.print_exc()
def start_cmd(bot, update): """Bot start command""" user = update.message.from_user # If user is here for the first time > Save him to the DB add_user_if_new(User(user.id, user.first_name, user.username, user.language_code)) keyboard = [[InlineKeyboardButton("Neuer Preisagent", callback_data="newPriceAgent"), InlineKeyboardButton("Meine Preisagenten", callback_data="myPriceAgents")]] reply_markup = InlineKeyboardMarkup(keyboard) bot.sendMessage(user.id, "Was möchtest du tun?", reply_markup=reply_markup) rm_state(user.id)
async def recvd_ph_no_message(_, message: Message): w_s_dict = AKTIFPERINTAH.get(message.chat.id) if not w_s_dict: return status_message = w_s_dict.get("START") if not status_message: return # await w_s_dict.get("START").delete() del w_s_dict["START"] status_message = await message.reply_text(RECVD_PHONE_NUMBER_DBP) loical_ci = User() w_s_dict["PHONE_NUMBER"] = message.text await loical_ci.connect() w_s_dict["SENT_CODE_R"] = await loical_ci.send_code( w_s_dict["PHONE_NUMBER"]) w_s_dict["USER_CLIENT"] = loical_ci status_message = await status_message.edit_text( ALREADY_REGISTERED_PHONE + "\n\n" + CONFIRM_SENT_VIA.format( AVAILABLE_CODE_RECVING_OPTIONS[w_s_dict["SENT_CODE_R"].type])) w_s_dict["MESSAGE"] = status_message AKTIFPERINTAH[message.chat.id] = w_s_dict raise message.stop_propagation()
from bot.context import * import threading from apscheduler.schedulers.background import BlockingScheduler from bot.user import User from time import sleep from datetime import datetime scheduler = BlockingScheduler() job = None # user = User(psw3()[0], psw3()[1]) user = User(psw2()[0], psw2()[1]) def work(): user.logger.log("starting bot... ") user.login() start = datetime.now() threads = [ threading.Thread(target=user.follow_following_followers), threading.Thread(target=user.like_following), threading.Thread(target=user.follow_followers), ] [x.start() for x in threads] [x.join() for x in threads] end = datetime.now() user.logger.log("duration ", end="") user.logger.log(end - start)
def test_user(self): u = User('localhost', 'bot', 'postgres', 'empty')
def _makeResponse(name, appointment): return Response( appointment.santa.chatId, 'Your target in group "' + name + '" is ' + User.makeMention(appointment.target), Response.MARKDOWN)
def __init__(self): self.user = User() self.bot = Bot(user=self.user.cookie, _id=self.user.response['id']) self.ws = None self.room = None self.engine, self.auth = None, None