示例#1
0
        public void TestConnect()
        {
            var slack = new Slack();

            Assert.IsTrue(slack.Init(Token), "Invalid Token");
            Assert.IsTrue(slack.Connect(), "Failed to Connect");
        }
示例#2
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            var    Instance = new Slack();
            string token    = "";
            bool   success;

            Instance.OnEvent += Instance_OnEvent;
            do
            {
                if (File.Exists("token.txt"))
                {
                    token = File.ReadAllText("token.txt");
                }
                if (String.IsNullOrWhiteSpace(token))
                {
                    Console.WriteLine("Please obtain a Token, and paste it below:");
                    token = Console.ReadLine();
                    File.WriteAllText("token.txt", token);
                }
                success = Instance.Init(token);
                if (!success)
                {
                    File.WriteAllText("token.txt", "");
                }
            } while (!success);
            Instance.Connect();
            while (Instance.Connecting || Instance.Connected)
            {
                Thread.Sleep(0);
            }
            Console.WriteLine("===Disconnected===");
            Console.ReadKey();
        }
示例#3
0
        public void TestStartValid()
        {
            if (String.IsNullOrWhiteSpace(Token))
            {
                Assert.Inconclusive("No valid token specified");
                return;
            }
            var slack = new Slack(Token);

            Assert.IsTrue(slack.Init());
        }
示例#4
0
        public void TestConnect()
        {
            if (String.IsNullOrWhiteSpace(Token))
            {
                Assert.Inconclusive("No valid token specified");
                return;
            }
            var slack = new Slack(Token);

            Assert.IsTrue(slack.Init(), "Invalid Token");
            Assert.IsTrue(slack.Connect(), "Failed to Connect");
        }
示例#5
0
        public void TestSend()
        {
            var slack = new Slack();

            Assert.IsTrue(slack.Init(Token), "Invalid Token");
            Assert.IsTrue(slack.Connect(), "Failed to Connect");
            while (!slack.RecievedHello)
            {
                Thread.Sleep(0);
            }
            slack.SendMessage(slack.GetChannel("#botspam").Id, "Test!");
            slack.SendMessage("#botspam", "Test2");
        }
示例#6
0
        public void PostToSlack()
        {
            if (shareToSlack == true && slackChannel != null)
            {
                if (slack == null)
                {
                    slack = gameObject.AddComponent <Slack>();
                }

                if (GetSlackToken() != null && GetSlackToken() != "")
                {
                    slack.Init(GetSlackToken(), slackChannel);
                    slack.PostVideoToChannel(videoName, GetVimeoPermalink());
                }
                else
                {
                    Debug.LogWarning("You are not signed into Slack.");
                }
            }
        }
示例#7
0
        public void TestStartValid()
        {
            var slack = new Slack();

            Assert.IsTrue(slack.Init(Token));
        }
示例#8
0
        public void TestStartInvalid()
        {
            var slack = new Slack();

            Assert.IsFalse(slack.Init("invalid"));
        }
示例#9
0
        static void Main(string[] args)
        {
            //AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;
            string confdir;

            Directory.CreateDirectory(confdir        = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Fingbot"));
            Environment.CurrentDirectory             = confdir;
            PersistentSingleton <Settings> .SavePath = "config.json";
#if REMINDERS
            PersistentSingleton <Reminders> .SavePath = "reminders.json";
#endif
            var settings = PersistentSingleton <Settings> .Instance;
            Singleton <NetworkData> .Instance.Refresh();

            //var missing = Singleton<NetworkData>.Instance.PickIncompleteHost();
            Singleton <NetworkData> .Instance.Save();

            var Slacks = settings.Tokens.Select(token => new Slack(token)).ToArray();
            if (Slacks.Length == 0)
            {
                Slack slack  = new Slack();
                bool  Authed = false;
                do
                {
                    if (String.IsNullOrEmpty(settings.Token))
                    {
                        Console.WriteLine("Please obtain a Token, and paste it below:");
                        settings.Token = Console.ReadLine();
                        PersistentSingleton <Settings> .Save();
                    }
                    slack  = new Slack(settings.Token);
                    Authed = slack.Init();
                    if (!Authed)
                    {
                        settings.Token = "";
                    }
                } while (Authed == false);
                Slacks = new Slack[] { slack };
            }
            foreach (var slack in Slacks)
            {
                slack.OnEvent += slack_OnEvent;
                Console.WriteLine("Connecting...");
                slack.Connect();
                Running = true;

                //var idlefunc = new Thread(new ThreadStart(IdleFunc(slack)));
                //idlefunc.Start();
            }
            int attempts = 0;
            while (Running)
            {
                foreach (var slack in Slacks)
                {
                    if (!slack.Connected)
                    {
                        try
                        {
                            Console.WriteLine("Reconnecting...");
                            slack.Connect();
                            attempts = 0;
                        }
                        catch (WebException c)
                        {
                            Console.WriteLine(c);
                            Thread.Sleep(new TimeSpan(0, attempts++, 1)); // Longer wait, because something's wrong.
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
        }