void commited on
Commit
2301569
1 Parent(s): edaa5d4

send chat for new followers

Browse files
Files changed (2) hide show
  1. USER_INFO.py +3 -0
  2. app.py +11 -7
USER_INFO.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ SESSDATA = ''
2
+ bili_jct = ''
3
+ buvid3 = ''
app.py CHANGED
@@ -11,12 +11,19 @@ import aiohttp
11
 
12
  import blivedm
13
  import blivedm.models.web as web_models
 
 
 
14
 
15
  # 直播间ID的取值看直播间URL
16
  TEST_ROOM_ID = 9792252
17
 
18
  # 这里填一个已登录账号的cookie的SESSDATA字段的值。不填也可以连接,但是收到弹幕的用户名会打码,UID会变成0
19
- SESSDATA = ''
 
 
 
 
20
 
21
  session: Optional[aiohttp.ClientSession] = None
22
 
@@ -29,12 +36,7 @@ async def dm_monitor():
29
  finally:
30
  await session.close()
31
 
32
-
33
  def init_session():
34
- cookies = http.cookies.SimpleCookie()
35
- cookies['SESSDATA'] = SESSDATA
36
- cookies['SESSDATA']['domain'] = 'bilibili.com'
37
-
38
  global session
39
  session = aiohttp.ClientSession()
40
  session.cookie_jar.update_cookies(cookies)
@@ -42,6 +44,8 @@ def init_session():
42
 
43
  async def run_single_client():
44
  room_id = TEST_ROOM_ID
 
 
45
  client = blivedm.BLiveClient(room_id, session=session)
46
  handler = MyHandler()
47
  client.set_handler(handler)
@@ -63,7 +67,7 @@ class MyHandler(blivedm.BaseHandler):
63
  uname = command['data']['uname']
64
  msg_type = command['data']['msg_type']
65
  if msg_type == 2:
66
- dmplayer.Pend(f'谢谢{uname}的关注喵', "bubu.wav")
67
 
68
  _CMD_CALLBACK_DICT['INTERACT_WORD'] = __interact_word_callback
69
 
 
11
 
12
  import blivedm
13
  import blivedm.models.web as web_models
14
+ from blivedm.clients.ws_base import BulletChat
15
+
16
+ import USER_INFO
17
 
18
  # 直播间ID的取值看直播间URL
19
  TEST_ROOM_ID = 9792252
20
 
21
  # 这里填一个已登录账号的cookie的SESSDATA字段的值。不填也可以连接,但是收到弹幕的用户名会打码,UID会变成0
22
+ cookies = http.cookies.SimpleCookie()
23
+ cookies['SESSDATA'] = USER_INFO.SESSDATA
24
+ cookies['SESSDATA']['domain'] = 'bilibili.com'
25
+ cookies['bili_jct'] = USER_INFO.bili_jct
26
+ cookies['buvid3'] = USER_INFO.buvid3
27
 
28
  session: Optional[aiohttp.ClientSession] = None
29
 
 
36
  finally:
37
  await session.close()
38
 
 
39
  def init_session():
 
 
 
 
40
  global session
41
  session = aiohttp.ClientSession()
42
  session.cookie_jar.update_cookies(cookies)
 
44
 
45
  async def run_single_client():
46
  room_id = TEST_ROOM_ID
47
+
48
+ global client
49
  client = blivedm.BLiveClient(room_id, session=session)
50
  handler = MyHandler()
51
  client.set_handler(handler)
 
67
  uname = command['data']['uname']
68
  msg_type = command['data']['msg_type']
69
  if msg_type == 2:
70
+ asyncio.create_task(client.send_bulletchat(BulletChat(msg=f'谢谢{uname}的关注喵')))
71
 
72
  _CMD_CALLBACK_DICT['INTERACT_WORD'] = __interact_word_callback
73