Skip to content

Commit

Permalink
feat: update bot
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 committed Feb 19, 2023
1 parent eff3146 commit 580c4e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

class Settings(BaseSettings):
telebot_token: str
url: str
moyu_url: str
api_url: str
api_token: str
uomg_url: str
chatgpt_prefix: str

class Config:
env_file = os.environ.get("ENV_FILE", ".env")
Expand Down
17 changes: 15 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def send_welcome(message: Message):

@bot.message_handler(commands=['se', 'sese', 'awsl'])
def send_awsl(message: Message):
res = requests.get(settings.url)
res = requests.get(f"{settings.api_url}/v2/random")
_logger.info("get url: %s - chat_id %s", res.text, message.chat.id)
bot.reply_to(message, res.text)


@bot.message_handler(commands=['moyu', 'mo', 'moyuban'])
def send_moyu(message: Message):
res = requests.get(settings.moyu_url)
res = requests.get(f"{settings.api_url}/moyu")
bot.reply_to(message, res.text)


Expand All @@ -43,5 +43,18 @@ def send_mjx(message: Message):
bot.reply_to(message, res.json()["imgurl"])


@bot.message_handler(func=lambda message: message.text.startswith(settings.chatgpt_prefix))
def send_gpt(message: Message):
res = requests.post(
f"{settings.api_url}/chatgpt",
json={
"token": settings.api_token,
"text": message.text.removeprefix(settings.chatgpt_prefix),
"chat_id": "telegram"
}
)
bot.reply_to(message, res.text)


_logger.info("start")
bot.infinity_polling()

0 comments on commit 580c4e7

Please sign in to comment.