Skip to content

Commit

Permalink
feat: 超我/天天超我, 回应消息中表情
Browse files Browse the repository at this point in the history
  • Loading branch information
fllesser committed Dec 6, 2024
1 parent e695ddb commit f5052eb
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
86 changes: 86 additions & 0 deletions nonebot_plugin_emojilike/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import json

from nonebot import logger, require, on_command, on_message, get_driver, get_bots
from nonebot.plugin import PluginMetadata
from nonebot.rule import Rule
from nonebot.adapters import Bot as BaseBot
from nonebot.adapters.onebot.v11 import Bot, MessageEvent
from .face import msg_emoji_id_set

require("nonebot_plugin_localstore")
require("nonebot_plugin_apscheduler")
from nonebot_plugin_apscheduler import scheduler
import nonebot_plugin_localstore as store

__plugin_meta__ = PluginMetadata(
name="链接分享解析器重制版",
description="nonebot2 名片赞,表情回应插件",
usage="赞我,超我,发送带表情的消息",
type="application",
homepage="https://github.com/fllesser/nonebot-plugin-emojilike",
supported_adapters={ "~onebot.v11" }
)


def contain_face(event: MessageEvent) -> bool:
return any(seg.type == "face" for seg in event.get_message())

emojilike = on_message(rule=Rule(contain_face))
cardlike = on_command(cmd=("赞我", "超我"))
sub_card_like = on_command(cmd=("天天赞我", "天天超我"))

@emojilike.handle()
async def _(bot: Bot, event: MessageEvent):
msg = event.get_message()
face_id_list = [seg.data.get('id') for seg in msg if seg.type == "face"]
for id in face_id_list:
if id in msg_emoji_id_set:
await bot.call_api("set_msg_emoji_like", message_id = event.message_id, emoji_id = id)

@cardlike.handle()
async def _(bot: Bot, event: MessageEvent):
id_set = {'76', '66', '63', '201', '10024'}
try:
for _ in range(5):
await bot.send_like(user_id = event.get_user_id(), times = 10)
await bot.call_api("set_msg_emoji_like", message_id = event.message_id, emoji_id = next(iter(id_set)))
except Exception as _:
await bot.call_api("set_msg_emoji_like", message_id = event.message_id, emoji_id = '38')


sub_like_set: set[int] = {}
sub_list_file = "sub_list.json"

@get_driver().on_startup
async def _():
data_file = store.get_plugin_data_file(sub_list_file)
if not data_file.exists():
data_file.write_text(json.dumps([]))
global sub_like_set
sub_like_set = set(json.loads(data_file.read_text()))
logger.info(f"每日赞/超列表: [{','.join(sub_like_set)}]")

@sub_card_like.handle()
async def _(bot: Bot, event: MessageEvent):
sub_like_set.add(event.user_id)
data_file = store.get_plugin_data_file(sub_list_file)
data_file.write_text(json.dumps(list(sub_like_set)))


@scheduler.scheduled_job(
"cron",
hour=20,
minute=7,
)
async def _():
bots: dict[str, BaseBot] = get_bots()
if not bots or len(bots) == 0:
return
for _, bot in bots:
if isinstance(bot, Bot):
for user_id in sub_like_set:
try:
for _ in range(5):
await bot.send_like(user_id = user_id, times = 10)
except Exception as _:
continue
11 changes: 11 additions & 0 deletions nonebot_plugin_emojilike/face.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msg_emoji_id_set: set[str] = {
'4','5','8','9','10','12','14','16','21','23','24','25','26','27','28','29','30','32','33','34','38','39','41','42','43',
'49','53','60','63','66','74','75','76','78','79','85','89','96','97','98','99','100','101','102','103','104','106','109',
'111','116','118','120','122','123','124','125','129','144','147','171','173','174','175','176','179','180','181','182','183',
'201','203','212','214','219','222','227','232','240','243','246','262','264','265','266','267','268','269','270','271','272',
'273','277','278','281','282','284','285','287','289','290','293','294','297','298','299','305','306','307','314','315','318',
'319','320','322','324','326','9728','9749','9786','10024','10060','10068','127801','127817','127822','127827','127836','127838',
'127847','127866','127867','127881','128027','128046','128051','128053','128074','128076','128077','128079','128089','128102',
'128104','128147','128157','128164','128166','128168','128170','128235','128293','128513','128514','128516','128522','128524',
'128527','128530','128531','128532','128536','128538','128540','128541','128557','128560','12856'
}
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "nonebot-plugin-emojilike"
version = "0.0.1"
description = "nonebot2 名片赞,表情回应插件"
authors = ["fllesser <[email protected]>"]
readme = "README.md"
packages = [{include = "nonebot_plugin_emojilike"}]
repository = "https://github.com/fllesser/nonebot-plugin-emojilike"
keywords = ["nonebot", "nonebot2", "emoji", "like"]

[tool.poetry.dependencies]
python = ">=3.9"
nonebot2 = ">=2.3.0"
nonebot-adapter-onebot = "*"
nonebot_plugin_localstore = ">=0.6.0"
nonebot-plugin-apscheduler = ">=0.5.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit f5052eb

Please sign in to comment.