Ejemplo n.º 1
0
 def do_add_mine(update: Update, _: CallbackContext) -> None:
     query = update.callback_query
     query.answer()
     query.delete_message()
     code = query.data
     info("用户" + update.effective_user.name + "添加了一条自选,代码为:" + code)
     user_id = update.effective_user.id
     session = requests.session()
     session.get("https://xueqiu.com/k?q=" + code, headers=header)
     res = session.get(
         "https://stock.xueqiu.com/v5/stock/batch/quote.json?symbol=" +
         code,
         headers=header)
     json_str = res.json()
     name = json_str['data']['items'][0]['quote']['name']
     if sql_funcs.sql_insert_mine(user_id, code, name):
         user = update.effective_user.name + ":\n"
         info("用户" + update.effective_user.name + "添加了一条自选成功,代码为:" + code)
         query.bot.send_message(chat_id=update.effective_chat.id,
                                text=user + "添加成功")
     else:
         user = update.effective_user.name + ":\n"
         warning("用户" + update.effective_user.name + "添加自选失败,代码为:" + code)
         query.bot.send_message(
             chat_id=update.effective_chat.id,
             text=user +
             "添加失败,您可能已经添加该股票或您已经达到自选添加上限。(上限为%s)" % max_mine_stock)
     return ConversationHandler.END
Ejemplo n.º 2
0
    def stock_list_mine(update: Update):
        try:
            query = update.callback_query
            user_id = update.effective_user.id
            stocks = sql_funcs.sql_select_all_mine(user_id)
            if stocks is None:
                user = update.effective_user.name + ":\n"
                warning("股票模块-自选功能-股票选择器:" + update.effective_user.name +
                        ":数据库中无自选股")
                query.bot.send_message(chat_id=update.effective_chat.id,
                                       text=user + "数据库内没有您的自选数据")
                return False
            else:
                keyboard = []
                for i in stocks:
                    describe = i[0] + "(股票代码" + i[1] + ")"
                    keyboard.append(
                        [InlineKeyboardButton(describe, callback_data=i[1])])
                reply_markup = InlineKeyboardMarkup(keyboard)
                user = update.effective_user.name + ":\n"

                query.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=user + "请选择股票",
                    reply_markup=reply_markup,
                )
                return True
        except:
            error("股票模块-自选模块-股票选择器异常")
            return False
Ejemplo n.º 3
0
def load_values():
    copy = default_data.copy()
    default_data.clear()
    try:
        with open("settings.json") as file:
            dumps = json.loads(file.read())
            default_data.update(**dumps)
    except FileNotFoundError:
        logger.warning("Can't find file \"settings.json\"! "
                       "Reload script to recreate it.")
        recreate(copy)
Ejemplo n.º 4
0
 def setu(update: Update, _: CallbackContext) -> None:
     try:
         query = update.callback_query
         query.answer()
         query.delete_message()
         url = ""
         r18 = 0
         if query.data == "R18":
             r18 = 1
             info("涩图模块:R18选择:是")
         else:
             info("涩图模块:R18选择:否")
         try:
             res = requests.get("https://api.lolicon.app/setu/?r18=" +
                                str(r18) + "&apikey=" + config.setu_Token)
             json_str = json.loads(res.text)
             if json_str['code'] == 401:
                 user = update.effective_user.name + ":\n"
                 text = user + "API接口超过调用限制(每令牌每天限制300)或API令牌被封禁"
                 warning("涩图模块" + text)
                 query.bot.send_message(chat_id=update.effective_chat.id,
                                        text=text)
             url = json_str['data'][0]['url']
             author = json_str['data'][0]['author']
             pid = json_str['data'][0]['pid']
             title = json_str['data'][0]['title']
             is_r = "否"
             if r18 != 0:
                 is_r = "是"
             user = update.effective_user.name + ":\n"
             text = user + "图片信息:\n" \
                           "作者:" + str(author) \
                    + "\n图片PID:" + str(pid) \
                    + "\n图片标题:" + str(title) \
                    + "\n是否R18:" + is_r
             info("涩图模块:" + text)
             query.bot.send_message(chat_id=update.effective_chat.id,
                                    text=text)
             info("涩图模块:发送图片" + url)
             query.bot.send_photo(chat_id=update.effective_chat.id,
                                  photo=url)
         except Exception as e:
             user = update.effective_user.name + ":\n"
             text = user + "服务器错误,错误原因:" + str(e) + "\n请自行访问链接:" + url
             error("涩图模块:" + text)
             query.bot.send_message(chat_id=update.effective_chat.id,
                                    text=text)
     except:
         error("涩图模块-涩图发送方法异常")
     return ConversationHandler.END
Ejemplo n.º 5
0
 def reset_db(update: Update, _: CallbackContext):
     input = update.message.text
     query = update.callback_query
     if str(input) != str(update.effective_user.id) or str(
             update.effective_user.id) not in admin_id:
         user = update.effective_user.name
         warning("管理员" + user + "在执行数据库重置时输入了错误的ID,执行被取消")
         text = user + ":\n" + "您输入的ID有误或无管理员权限,数据库的重置已取消"
         update.message.reply_text(text=text)
         return ConversationHandler.END
     if not reset_database():
         user = update.effective_user.name
         error("管理员" + user + "在执行数据库重置时发生了数据库错误,数据库重置失败")
         text = user + ":\n" + "在执行数据库重置时发生了数据库错误,数据库重置失败"
         update.message.reply_text(text=text)
     else:
         user = update.effective_user.name
         warning("管理员" + user + "重置了数据库")
         text = user + ":\n" + "数据库重置成功"
         update.message.reply_text(text=text)
     return ConversationHandler.END
Ejemplo n.º 6
0
 def admin_select(update: Update, _: CallbackContext) -> int:
     try:
         id = update.effective_user.id
         if str(id) not in admin_id:
             user = update.effective_user.name
             warning("管理员模块:一名非管理员用户" + user + "请求访问管理功能")
             text = user + ":\n" + "您不是管理员,没有本指令权限!\n" \
                                   "如果您是管理员,请先将您的ID添加如配置文件"
             update.message.reply_text(text)
             return ConversationHandler.END
         keyboard = [[InlineKeyboardButton("数据库", callback_data='数据库')],
                     [InlineKeyboardButton("日志", callback_data='日志')]]
         reply_markup = InlineKeyboardMarkup(keyboard)
         user = update.effective_user.name
         text = user + ":\n" + '请选择管理功能'
         info("管理员模块:一名管理员" + user + "选择了管理员功能")
         update.message.reply_text(
             text,
             reply_markup=reply_markup,
         )
         return ADMIN_SELECT
     except Exception as e:
         error("管理员模块异常:" + str(e))
Ejemplo n.º 7
0
def cancel(update: Update, _: CallbackContext) -> int:
    user = update.effective_user.name + ":\n"
    warning(update.effective_user.name + "取消了当前正在运行的命令")
    update.message.reply_text(user + '命令结束')
    return ConversationHandler.END
Ejemplo n.º 8
0
import module.setu as setu
import module.sentence as sentence
import module.bili as bili
import module.weibo as weibo
import module.english as english
import module.zhihu as zhihu
import module.get_me as get_me
import module.admin as admin

logger_start_check()
info("主进程:日志文件检查完成")
info("主进程:开始进行数据库检查")
# 数据库与Token检查
if not sql_funcs.sql_start_check():
    error("主进程:数据库创建或读取错误,请检查")
    warning("主进程:程序由于异常导致退出")
    exit(1)
info("主进程:数据库检查完成")

if config.Token == "":
    error("主进程:配置文件错误,请先在config.py中输入对应Token后使用")
    warning("主进程:程序由于异常导致退出")
    exit(1)

if len(config.admin_id) == 0:
    warning("您未添加管理员,管理员功能将不可用")

info("主进程:配置文件检查完成")

# 初始化Telegram-Bot
updater = Updater(token=config.Token, use_context=True)
Ejemplo n.º 9
0
    def fast_list_all_mine(update, context):
        try:
            stocks = sql_funcs.sql_select_all_mine(update.effective_user.id)
            if stocks is None:
                user = update.effective_user.name + ":\n"
                text = user + "数据库中没有您的自选信息"
                warning("股票模块-快速打印简报方法:" + text)
                context.bot.send_message(chat_id=update.effective_chat.id,
                                         text=text)
            else:
                text = ""
                for i in stocks:
                    try:
                        session = requests.session()
                        session.get("https://xueqiu.com/k?q=" + i[1],
                                    headers=header)
                        res = session.get(
                            "https://stock.xueqiu.com/v5/stock/batch/quote.json?symbol="
                            + i[1],
                            headers=header)
                        json_str = res.json()
                        # 股票名
                        name = json_str['data']['items'][0]['quote']['name']
                        # 数据时间
                        dt = json_str['data']['items'][0]['quote']['time']
                        if dt is not None:
                            time_local = time.localtime(dt / 1000)
                            dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
                        # 交易状态
                        status = json_str['data']['items'][0]['market'][
                            'status']

                        # 现价
                        current = json_str['data']['items'][0]['quote'][
                            'current']
                        # 昨收
                        end_price = json_str['data']['items'][0]['quote'][
                            'last_close']
                        # 跌涨数
                        cost = 0
                        if current is not None and end_price is not None:
                            cost = current - end_price
                        # 跌涨率%
                        rate = 0
                        if cost is not None and end_price is not None and cost != 0:
                            rate = cost / end_price

                        cost = float(format(cost, ".2f"))
                        if cost > 0:
                            cost = "+" + str(cost)
                        rate = float(format(rate * 100, ".2f"))
                        if rate > 0:
                            rate = "+" + str(rate)

                        text += "%s" % dt
                        text += "(%s)\n" % status
                        text += "%s " % name
                        text += "(%s)\n" % i[1]
                        text += "现价:%s " % current
                        text += "(%s " % cost
                        text += ",%s%%)\n\n" % rate

                    except Exception as e:
                        user = update.effective_user.name + ":\n"
                        text = user + "服务器错误,错误原因:" + str(e)
                        error("股票模块-快速打印简报方法:" + text)
                        context.bot.send_message(
                            chat_id=update.effective_chat.id, text=text)
                        return
                info("股票模块-快速打印简报方法:成功获取用户" + update.effective_user.name +
                     "的" + str(len(stocks)) + "条股票数据")
                user = update.effective_user.name + ":\n"
                context.bot.send_message(chat_id=update.effective_chat.id,
                                         text=user + text)
        except:
            error("股票模块-快速打印简报方法异常")