-
Notifications
You must be signed in to change notification settings - Fork 0
/
acg.py
38 lines (30 loc) · 1.21 KB
/
acg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import re
import requests
from plugins import register, Plugin, Event, logger, Reply, ReplyType
@register
class Acg(Plugin):
name = "acg"
def did_receive_message(self, event: Event):
pass
def will_generate_reply(self, event: Event):
query = event.context.query
if query == self.config.get("command"):
event.reply = self.reply()
event.bypass()
def will_decorate_reply(self, event: Event):
pass
def will_send_reply(self, event: Event):
pass
def help(self, **kwargs) -> str:
return "Use the command #acg(or whatever you like set with command field in the config) to obtain an anime-style image"
def reply(self) -> Reply:
reply = Reply(ReplyType.TEXT, "Failed to get acg image")
try:
response = requests.get("https://api.oick.cn/api/random/", timeout=30, verify=False)
if response.status_code == 200:
reply = Reply(ReplyType.IMAGE, "https://api.oick.cn/api/random/")
else:
logger.error(f"Abnormal site status, request: {response.status_code}")
except Exception as e:
logger.error(f"Video api call error: {e}")
return reply