Example #1
0
        public static void Initialize()
        {
            //load the commands list
            foreach (var m in typeof(Commands).GetMethods())
            {
                var c = new Command();
                foreach (var a in m.GetCustomAttributes(true))
                {
                    if (a is Attributes.Command)
                    {
                        var ca = a as Attributes.Command;
                        c.Blockable = ca.Blockable;
                        c.DevOnly = ca.DevOnly;
                        c.GlobalAdminOnly = ca.GlobalAdminOnly;
                        c.GroupAdminOnly = ca.GroupAdminOnly;
                        c.Trigger = ca.Trigger;
                        c.Method = (ChatCommandMethod)Delegate.CreateDelegate(typeof(ChatCommandMethod), m);
                        c.InGroupOnly = ca.InGroupOnly;
                        Commands.Add(c);
                    }
                }
            }

            Api.UpdateReceived += UpdateHandler.UpdateReceived;
            Api.CallbackQueryReceived += UpdateHandler.CallbackReceived;
            Api.ReceiveError += ApiOnReceiveError;
            Me = Api.GetMe().Result;
            //wait for a node to connect...
            //#if !DEBUG
            //            while (Nodes.Count == 0)
            //            {
            //                Thread.Sleep(100);
            //            }
            //#endif
            StartTime = DateTime.UtcNow;
            //now we can start receiving
            Api.StartReceiving();
            //new Task(SendOnline).Start();
        }
Example #2
0
        public static void Initialize()
        {
            //get api token from registry
            var key =
                    RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
                        .OpenSubKey("SOFTWARE\\Werewolf");
            #if DEBUG
            TelegramAPIKey = key.GetValue("DebugAPI").ToString();
            #else
            TelegramAPIKey = key.GetValue("ProductionAPI").ToString();
            #endif
            Api = new Client(TelegramAPIKey);

            //load the commands list
            foreach (var m in typeof(Commands).GetMethods())
            {
                var c = new Command();
                foreach (var a in m.GetCustomAttributes(true))
                {
                    if (a is Attributes.Command)
                    {
                        var ca = a as Attributes.Command;
                        c.Blockable = ca.Blockable;
                        c.DevOnly = ca.DevOnly;
                        c.GlobalAdminOnly = ca.GlobalAdminOnly;
                        c.GroupAdminOnly = ca.GroupAdminOnly;
                        c.Trigger = ca.Trigger;
                        c.Method = (ChatCommandMethod)Delegate.CreateDelegate(typeof(ChatCommandMethod), m);
                        c.InGroupOnly = ca.InGroupOnly;
                        Commands.Add(c);
                    }
                }
            }

            Api.UpdateReceived += UpdateHandler.UpdateReceived;
            Api.CallbackQueryReceived += UpdateHandler.CallbackReceived;
            Api.ReceiveError += ApiOnReceiveError;
            Me = Api.GetMe().Result;

            StartTime = DateTime.UtcNow;
            //now we can start receiving
            Api.StartReceiving();
        }