public bool sendMessage(JObject job) { //https://api.vc.bilibili.com/web_im/v1/web_im/send_msg Dictionary <string, string> kvs = new Dictionary <string, string>(); CookieCollection ck = sess.CookieContext; kvs.Add("msg[sender_uid]", ck["DedeUserID"].Value); kvs.Add("msg[receiver_id]", talker_id.ToString()); kvs.Add("msg[receiver_type]", "1"); kvs.Add("msg[msg_type]", "2"); kvs.Add("msg[msg_status]", "0"); kvs.Add("msg[content]", job.ToString()); kvs.Add("msg[new_face_version]", "0"); kvs.Add("msg[timestamp]", TimestampHandler.GetTimeStamp(DateTime.Now).ToString()); kvs.Add("msg[dev_id]", "A8DF21F2-98F7-43A6-9EB4-E348F9B41EBC");//暂时不知道如何生成,但该项似乎不影响私信的发送 kvs.Add("build", "0"); kvs.Add("mobi_app", "web"); kvs.Add("csrf_token", ck["bili_jct"].Value); kvs.Add("from_firework", "0"); kvs.Add("csrf", ck["bili_jct"].Value); string response = sess._post_with_cookies("https://api.vc.bilibili.com/web_im/v1/web_im/send_msg", kvs); if (response == "") { return(false); } JObject raw_json = (JObject)JsonConvert.DeserializeObject(response); return(raw_json.Value <int>("code") == 0); }
private static void Receiver_ReceivedDanmaku(object sender, ReceivedDanmakuArgs e) { var d = e.Danmaku; string guid = ""; switch (d.MsgType) { case MsgTypeEnum.GuardBuy: guid = Guid.NewGuid().ToString("N"); db.logCREW(d.UserID, d.UserGuardLevel, d.GiftCount, TimestampHandler.GetTimeStamp(DateTime.Now), guid); break; case MsgTypeEnum.LiveEnd: lid = -1; break; } db.logDMK(TimestampHandler.GetTimeStamp16(DateTime.Now), d.RawData, lid, guid); }
private static void StreamStarted(object sender, StreamStartedArgs e) { lid = TimestampHandler.GetTimeStamp(DateTime.Now); }
public void Receiver_ReceivedDanmaku(object sender, ReceivedDanmakuArgs e) { MainHolder.pool.submitWorkload(() => { try { JObject json = (JObject)JsonConvert.DeserializeObject(e.Danmaku.RawData); MainHolder.tms.sendDanmakuToCli(e.Danmaku.RawData); switch (e.Danmaku.MsgType) { case MsgTypeEnum.Comment: if (e.Danmaku.IsAdmin) { Log(ConsoleColor.Yellow, "<房管>" + e.Danmaku.UserName + "#" + e.Danmaku.UserID + " > "); } else { Log(ConsoleColor.Gray, e.Danmaku.UserName + "#" + e.Danmaku.UserID + " > "); } Log(ConsoleColor.White, e.Danmaku.CommentText + "\n"); int ml = GetMedalLevelMatchUID(streamer_id, json); if (ml >= 10) { if (!tlist.ContainsKey(e.Danmaku.UserName)) { tlist.Add(e.Danmaku.UserName, ml); } } { int mainsite_level = GetUserMainSiteLevel(json); var uid = GetUserUID(json); /*if (ml < 1//粉丝牌子小于1级 * && mainsite_level < 1//主站等级小于一级 * ) * { * blr.manage.banUID(uid); * Log(ConsoleColor.White, uid + "被直播间自动封禁"); * var user = BiliUser.getUser(uid, MainHolder.biliapi); * MainHolder.broadcaster.BroadcastToAdminGroup(user.name + "#" + user.uid + "\n直播间中被自动封禁:\n" + * ((ml < 1) ? "牌子等级:" + ml + "<1\n" : "") + * ((ml < 1) ? "主站等级:" + mainsite_level + "<1\n" : "") * ); * }*/ } DataBase.me.recBLiveDanmaku(e.Danmaku.UserID, e.Danmaku.CommentText, TimestampHandler.GetTimeStamp(DateTime.Now), lid); if (!DataBase.me.isBiliUserExist(e.Danmaku.UserID)) { new_commers++; } if (!viewerlist.Contains(e.Danmaku.UserID)) { viewerlist.Add(e.Danmaku.UserID); } DataBase.me.addBiliUser(e.Danmaku.UserID, e.Danmaku.UserName); { List <string> bwords = DataBase.me.listBiliveBanwords(); foreach (string bword in bwords) { if (e.Danmaku.CommentText.IndexOf(bword) >= 0) { MainHolder.broadcaster.BroadcastToAdminGroup("直播间检测到疑似违规弹幕:\n" + e.Danmaku.CommentText + "\n发送者:" + e.Danmaku.UserName + "(" + e.Danmaku.UserID + ")"); } } } if (e.Danmaku.CommentText.ToUpper() == "MARK") { if (lid < 0) { blr.sendDanmaku("无法标记:不在直播"); } string id = doMark(e.Danmaku.UserID, TimestampHandler.GetTimeStamp(DateTime.Now)); MainHolder.broadcaster.BroadcastToAdminGroup("放置了一个标记\n" + e.Danmaku.UserName + "#" + e.Danmaku.UserID + "\n标记点ID:" + id); } break; case MsgTypeEnum.GuardBuy: string dpword = "??未知??"; if (!DataBase.me.isBiliUserExist(e.Danmaku.UserID)) { new_commers++; } if (!viewerlist.Contains(e.Danmaku.UserID)) { viewerlist.Add(e.Danmaku.UserID); } DataBase.me.addBiliUser(e.Danmaku.UserID, e.Danmaku.UserName); int coin_gold_ = 0; switch (e.Danmaku.UserGuardLevel) { case 1: coin_gold_ = 19998000; dpword = "总督"; break; case 2: coin_gold_ = 1998000; dpword = "提督"; break; case 3: coin_gold_ = 158000; dpword = "舰长"; break; } gold_coins += coin_gold_; bool isnew = !DataBase.me.isBiliUserGuard(e.Danmaku.UserID); if (lid > 0) { if (isnew) { MainHolder.broadcaster.BroadcastToAdminGroup("欢迎新" + dpword + "!\n" + e.Danmaku.UserName + " #" + e.Danmaku.UserID + "\n时长:" + e.Danmaku.GiftCount); if (MainHolder.useBiliRecFuncs) { if (MainHolder.useBiliRecFuncs) { blr.sendDanmaku("欢迎新" + dpword + "!请留意私信哦~"); } } } else { MainHolder.broadcaster.BroadcastToAdminGroup("欢迎" + dpword + "续航!\n" + e.Danmaku.UserName + " #" + e.Danmaku.UserID + "\n时长:" + e.Danmaku.GiftCount); if (MainHolder.useBiliRecFuncs) { blr.sendDanmaku("欢迎<" + e.Danmaku.UserName + ">续航!"); } } } else { if (isnew) { MainHolder.broadcaster.BroadcastToAdminGroup("侦测到虚空·新" + dpword + "\n" + e.Danmaku.UserName + " #" + e.Danmaku.UserID + "\n时长:" + e.Danmaku.GiftCount); if (MainHolder.useBiliRecFuncs) { blr.sendDanmaku("虚空·新" + dpword + " 已记录 请留意私信~"); } } else { MainHolder.broadcaster.BroadcastToAdminGroup("侦测到虚空·" + dpword + "续航\n" + e.Danmaku.UserName + " #" + e.Danmaku.UserID + "\n时长:" + e.Danmaku.GiftCount); if (MainHolder.useBiliRecFuncs) { blr.sendDanmaku("侦测到虚空续航,嘀嘀嘀~"); } } } DataBase.me.recUserBuyGuard(e.Danmaku.UserID, e.Danmaku.GiftCount, e.Danmaku.UserGuardLevel, lid); //int timestamp = e.Danmaku; //if (timestamp < 1600000000) //{ var timestamp = TimestampHandler.GetTimeStamp(DateTime.Now); //使用备用时间戳生成方式 //} SendKeyToCrewMember(e.Danmaku.UserID, e.Danmaku.GiftCount, e.Danmaku.UserGuardLevel, timestamp, dpword, isnew); break; case MsgTypeEnum.GiftSend: string cointype = json["data"].Value <string>("coin_type"); //silver | gold int coins = json["data"].Value <int>("total_coin"); if (cointype == "silver") { selver_coins += coins; } else { gold_coins += coins; } DataBase.me.recBGift(lid, e.Danmaku.UserID, cointype, coins, e.Danmaku.GiftName); if (!DataBase.me.isBiliUserExist(e.Danmaku.UserID)) { new_commers++; } if (!viewerlist.Contains(e.Danmaku.UserID)) { viewerlist.Add(e.Danmaku.UserID); } DataBase.me.addBiliUser(e.Danmaku.UserID, e.Danmaku.UserName); break; case MsgTypeEnum.Welcome: if (!DataBase.me.isBiliUserExist(e.Danmaku.UserID)) { new_commers++; } if (!viewerlist.Contains(e.Danmaku.UserID)) { viewerlist.Add(e.Danmaku.UserID); } DataBase.me.addBiliUser(e.Danmaku.UserID, e.Danmaku.UserName); break; case MsgTypeEnum.LiveEnd: StreamStopped(); break; default: JObject obj = JObject.Parse(e.Danmaku.RawData); if (obj["cmd"]?.ToObject <string>() == "ROOM_BLOCK_MSG") { List <int> tobebanned = DataBase.me.listPermbans(); int uid = (int)obj["uid"]?.ToObject <int>(); string name = obj["uname"]?.ToObject <string>(); if (tobebanned.Contains(uid)) { break; } //MainHolder.broadcaster.BroadcastToAdminGroup("【直播间禁言】\n" + name + "#" + uid + "被禁言。\n使用\"#bpban " + uid + "\"可将其永久封禁。"); //if (MainHolder.useBiliRecFuncs) MainHolder.bilidmkproc.blr.sendDanmaku(name + "被禁言"); DataBase.me.recBLiveBan(lid, uid, -1); } break; } } catch (Exception err) { MainHolder.broadcaster.BroadcastToAdminGroup("[Exception]\n这条消息可能意味着机器人发生了错误。它仍在继续运行,但可能不是很稳定。下面的信息用来帮助鸡蛋定位错误,管理不必在意。\n[弹幕监视]\nMessageLoop工作正常,该错误不会影响其它弹幕接收。\n\n" + err.Message + "\n\n堆栈跟踪:\n" + err.StackTrace); } }); }