Ejemplo n.º 1
0
        public async Task <bool> doAuthorization(DMPlugin plugin)
        {
            var result = await LoginCenterAPI.doAuthorization(plugin);

            return(result == AuthorizationResult.Success);
        }
Ejemplo n.º 2
0
 public bool checkAuthorization(DMPlugin plugin)
 {
     return(LoginCenterAPI.checkAuthorization(plugin) == LoginCenter.API.AuthorizationResult.Success);
 }
Ejemplo n.º 3
0
 public Task <string> trySendMessage(int roomid, string msg, int color = 16777215, int mode = 1, int rnd = -1, int fontsize = 25)
 {
     return(LoginCenterAPI.trySendMessage(roomid, msg, color, mode, rnd, fontsize));
 }
Ejemplo n.º 4
0
 public bool checkAuthorization()
 {
     return(LoginCenterAPI.checkAuthorization());
 }
Ejemplo n.º 5
0
 internal SafeAPI()
 { // 尝试触发报错
     LoginCenterAPI.checkAuthorization();
 }
Ejemplo n.º 6
0
 internal async Task <AuthorizationResult> doAuth(BilibiliDM_PluginFramework.DMPlugin plugin)
 {
     return(await LoginCenterAPI.doAuthorization(plugin));
 }
Ejemplo n.º 7
0
        private async void input_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (input.Text.Contains("\n"))
                {
                    string text = input.Text.Replace("\r", string.Empty).Replace("\n", string.Empty);
                    input.Text = string.Empty;
                    history    = 0;
                    add2List(text);
                    string result = null;
                    try
                    {
                        if (SendDanmakuMain.self.RoomId.HasValue)
                        {
                            result = await SendDanmakuAsync(SendDanmakuMain.self.RoomId.Value, text, LoginCenterAPI.getCookies());

                            //string.Join("; ", LoginCenterAPI.getCookies().GetCookies(new Uri("http://live.bilibili.com/")).OfType<Cookie>().Select(p => $"{p.Name}={p.Value}"))
                            //result = await SendDanmakuMain.api.send(SendDanmakuMain.self.RoomId.Value, text);
                        }
                        else
                        {
                            SendDanmakuMain.log("还未连接直播间!");
                            return;
                        }
                    }
                    catch (PluginNotAuthorizedException)
                    {
                        SendDanmakuMain.log("插件未被授权使用B站账号");
                        return;
                    }
                    if (result == null)
                    {
                        SendDanmakuMain.log("网络错误,请重试");
                    }
                    else
                    {
                        var    j   = JObject.Parse(result);
                        string msg = (j["msg"] ?? j["message"]).ToString();
                        if (msg != string.Empty)
                        {
                            SendDanmakuMain.log("服务器返回:" + msg);
                        }
                    }
                }
            }
            finally
            {// 统计弹幕字数
                text_count.Text = input.Text.Length.ToString();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 用户输入监听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void input_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (input.Text != string.Empty)
                {
                    if (input.Text.Substring(input.Text.Length - 1, 1) == "\n")
                    {
                        if (input.Text.Remove(1, input.Text.Length - 1) == "/")
                        {
                            string[] sArray = Regex.Split(input.Text.Remove(0, 1).Replace("\r", string.Empty).Replace("\n", string.Empty), " ", RegexOptions.IgnoreCase);
                            switch (DeveloperModeSet(sArray))
                            {
                            case 0:
                                help_Text.Text = "指令 " + sArray[1] + " 执行成功!";
                                return;

                            case 1:
                                help_Text.Text = "指令 " + sArray[1] + " 的执行已被取消!";
                                return;

                            case 2:
                                help_Text.Text = "指令 " + sArray[1] + " 的执行出现错误!";
                                return;

                            case 3:
                                help_Text.Text = "指令 " + sArray[1] + " 的执行出现未知错误!";
                                return;

                            default:
                                help_Text.Text = "指令 " + sArray[1] + " 的未能被识别!将作为弹幕进行发送。";
                                break;
                            }
                        }

                        help_Text.Text = "发送中...";
                        string text = input.Text.Replace("\r", string.Empty).Replace("\n", string.Empty);
                        input.Text = string.Empty;
                        history    = 0;
                        add2List(text);
                        string result = null;
                        try
                        {
                            if (SendDanmakuMain.self.RoomId.HasValue)
                            {
                                result = await SendDanmakuAsync(SendDanmakuMain.self.RoomId.Value, text, LoginCenterAPI.getCookies());

                                //string.Join("; ", LoginCenterAPI.getCookies().GetCookies(new Uri("http://live.bilibili.com/")).OfType<Cookie>().Select(p => $"{p.Name}={p.Value}"))
                                //result = await SendDanmakuMain.api.send(SendDanmakuMain.self.RoomId.Value, text);
                            }
                            else
                            {
                                SendDanmakuMain.log("还未连接直播间!");
                                help_Text.Text = "还未连接至直播间!";
                                return;
                            }
                        }
                        catch (PluginNotAuthorizedException)
                        {
                            SendDanmakuMain.log("插件未被授权使用B站账号");
                            help_Text.Text = "插件未被授权使用B站账号";
                            return;
                        }

                        if (result == null)
                        {
                            SendDanmakuMain.log("网络错误,请重试");
                            help_Text.Text = "网络错误,请重试";
                            return;
                        }
                        else
                        {
                            var    j   = JObject.Parse(result);
                            string msg = (j["msg"] ?? j["message"]).ToString();
                            if (msg != string.Empty)
                            {
                                SendDanmakuMain.log("服务器返回:" + msg);
                                help_Text.Text = "错误:" + msg;
                                return;
                            }
                        }
                        help_Text.Text = "已发送!";
                    }
                }
            }
            finally
            {// 统计弹幕字数
                text_count.Text = input.Text.Length.ToString();
                if (input.Text.Length >= input.MaxLength)
                {
                    text_count.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                }
                else
                {
                    text_count.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                }
            }
        }