Skip to content

Commit

Permalink
perform checkin on DM_INTRERACTION keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
TZFC committed Jan 11, 2024
1 parent 26b46ff commit cc298b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
33 changes: 33 additions & 0 deletions EventHandler/OTHER_handler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import asyncio
from datetime import datetime
from json import loads

from Utils.Checkin import record_checkin
from Utils.EVENT_IDX import *
from Utils.RecordDanmaku import record_danmaku
from Utils.SendReportCheckin import send_report_checkin
from Utils.TopCheckin import get_top_checkin
from web.UpdatePage import update_page


async def handle_dm_interaction(event, database, master_config, room_info):
Expand All @@ -11,6 +16,34 @@ async def handle_dm_interaction(event, database, master_config, room_info):
data = loads(event['data']['data']['data'])
content = "--" + data['combo'][0]['content']
id = event['data']['data']['id']
if any(live_end_word in data['combo'][0]['content'] for live_end_word in {"晚安", "午安", "拜拜"}):
info = await room_info['live_room'].get_room_info()
live_status = info['room_info']['live_status']
if live_status == LIVE_STATUS_STREAMING \
and room_info['room_config']["feature_flags"]["checkin"] \
and not room_info['state']['pre-checkin']:
async with asyncio.TaskGroup() as tg:
with database.cursor() as cursor:
sql = "SELECT start FROM liveTime WHERE room_id = %s AND end IS NULL AND summary IS NULL"
val = (room_id,)
cursor.execute(sql, val)
start_time = cursor.fetchall()[0][0]
# 统计直播间发言人
await record_checkin(start_time=start_time,
end_time=datetime.fromtimestamp(event['data']["info"][TIMESTAMP_IDX]['ts']),
master=room_info['room_config']['master'],
room_id=room_id,
checkin_days=room_info['room_config']['checkin_days'],
database=database)
top_uid_name_count = await get_top_checkin(master_uid=room_info['master_credential'].dedeuserid,
room_id=room_id, database=database)
tg.create_task(send_report_checkin(live_room=room_info['live_room'],
top_uid_username_count=top_uid_name_count))
tg.create_task(update_page(target=f"/var/www/html/{room_id}.html",
checkin_days=room_info['room_config']['checkin_days'],
content=top_uid_name_count))
room_info['state']['pre-checkin'] = True
return
await record_danmaku(name="他们都在说", received_uid=0, time=datetime.now().replace(microsecond=0),
medal_room=room_id, medal_level=99, text=content, message_type=TEXT_TYPE, room_id=room_id,
danmu_id=id, database=database)
Expand Down
4 changes: 2 additions & 2 deletions Utils/SendReportCheckin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ async def send_report_checkin(live_room, top_uid_username_count):
if rank >= 10:
break
text = f"第{rank + 1}{username} 打卡{count}次"
for chunk in range(len(text)//20+1):
for chunk in range(len(text) // 20 + 1):
await asyncio.sleep(5)
await live_room.send_danmaku(Danmaku(text[chunk*20:(chunk+1)*20]), reply_mid=uid)
await live_room.send_danmaku(Danmaku(text[chunk * 20:(chunk + 1) * 20]), reply_mid=uid)
2 changes: 1 addition & 1 deletion master.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def live_end(event):
@__live_danmaku.on("DISCONNECT")
async def disconnect(event):
__event_room_id = event['room_display_id']
await refresh_credentials(masters=[roomInfos[__event_room_id]['room_config']['master'],],
await refresh_credentials(masters=[roomInfos[__event_room_id]['room_config']['master'], ],
room_infos=roomInfos,
database=mydb)

Expand Down

0 comments on commit cc298b0

Please sign in to comment.