コード例 #1
0
        private void Discord_MessageReceived(object sender, MessageEventArgs e)
        {
            string      firstWord    = Regex.Match(e.Message.Text, @"^\S+\b").Value.ToLower();
            UserCommand foundCommand = MainWindow.colBotCommands.FirstOrDefault(x =>
                                                                                x.Command == firstWord);

            if (foundCommand != null)
            {
                //foundCommand.ExecuteCommand(new IrcMessage(e.User.Name + "@Discord", e.Message.Text));
                foundCommand.ExecuteCommandDiscord(e.Message);
            }
            else
            {
                //BotCommands.RunBotCommand(firstWord, new IrcMessage(e.User.Name + "@Discord", e.Message.Text));
                BotCommands.RunBotCommandDiscord(firstWord, e.Message);
            }
            if (e.Channel.IsPrivate)
            {
                if (e.Message.Text.Split(' ')[0] == "confirm" && e.Message.Text.Split(' ').Length == 2)
                {
                    Discord.User   confirm = e.User;
                    Models.Channel target  = client.GetChannel(e.Message.Text.Split(' ')[1]);
                    string         id      = target.Game;
                    if (id == confirm.Id.ToString())
                    {
                        Viewer vwr = colDatabase.FirstOrDefault(x => x.UserName.ToLower() == target.Name.ToLower());
                        vwr.DiscordID = confirm.Id.ToString();
                        DatabaseUtils.UpdateViewer(vwr);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Giveaway.cs プロジェクト: cozyGalvinism/DergBot
 public void Start()
 {
     //TimerCallback cb = delegate (object o)
     //{
     //    running = false;
     //    MainWindow.instance.botChatConnection.SendChatMessage(string.Format("{0} giveaway ended! Winner will be drawn by the streamer!", giveawayName));
     //};
     //giveawayTimer = new Timer(cb, new ManualResetEvent(true), new TimeSpan(0), giveawayTime);
     running = true;
     MainWindow.instance.botChatConnection.ChatMessageReceived += BotChatConnection_ChatMessageReceived;
     BotCommands.SendAndShowMessage(string.Format("{0} giveaway has started! Type {1} in chat to enter! Following is {2} Duration: {3}h {4}m {5}s", giveawayName, keyword, (needsFollow ? "needed." : "not needed."), giveawayTime.Hours, giveawayTime.Minutes, giveawayTime.Seconds));
 }
コード例 #3
0
ファイル: Giveaway.cs プロジェクト: cozyGalvinism/DergBot
 public void Stop()
 {
     giveawayTimer.Dispose();
     running = false;
     BotCommands.SendAndShowMessage(string.Format("{0} giveaway ended! Winner will be drawn by the streamer!", giveawayName));
 }
コード例 #4
0
 public void DefaultGiveawayWinnerChosen(object sender, WinnerChosenEventArgs e)
 {
     BotCommands.SendAndShowMessage(string.Format("{0} has won the {1} giveaway!", e.Winner.UserName, e.Giveaway.GiveawayName));
     btnDrawWinner.IsEnabled = true;
     WindowViewerChat vc = new WindowViewerChat(this, e.Winner);
 }
コード例 #5
0
 public void DefaultGiveawayViewerEntered(object sender, ViewerEnteredEventArgs e)
 {
     BotCommands.SendAndShowMessage(string.Format("{0} has entered the {1} giveaway!", e.Viewer, e.Giveaway.GiveawayName));
 }
コード例 #6
0
        internal void Run()
        {
            while (true)
            {
                //IrcMessage ircMessage = new IrcMessage(ircClient.ReadLine(), connectedUser);
                string     rm         = ircClient.ReadLine();
                IrcMessage ircMessage = new IrcMessage(rm, connectedUser);
                Trace.WriteLine(rm);

                // Bot account is the main chat account
                if (isBot)
                {
                    switch (ircMessage.Command)
                    {
                    case "PING":     // Received PING
                        ircClient.WriteLine("PONG");
                        break;

                    case "MODE":     // Received MODE
                        if (ircMessage.Args[1] == "+o")
                        {
                            // Set throttle for current user as operator
                            if (ircMessage.Args[2] == connectedUser.UserName)
                            {
                                ircClient.throttle = 350;
                            }
                        }
                        else if (ircMessage.Args[1] == "-o")
                        {
                            // Set throttle for current user as member
                            if (ircMessage.Args[2] == connectedUser.UserName)
                            {
                                ircClient.throttle = 1550;
                            }
                        }
                        break;

                    // Received a list of joined viewers
                    case "353":
                        string[] viewers = ircMessage.Message.Split(' ');
                        foreach (string username in viewers)
                        {
                            Utils.AddToViewersCol(username);
                        }
                        break;

                    // JOIN Event
                    case "JOIN":
                        Utils.AddToViewersCol(ircMessage.Author);
                        break;

                    // PART Event
                    case "PART":
                        Utils.RemoveFromViewersCol(ircMessage.Author);
                        break;

                    // PRIVMSG (Chat Message Received) Event
                    case "PRIVMSG":
                        ChatMessageReceived(this, new ChatMessageReceivedEventArgs(ircMessage));
                        // Seeing that JOIN Message is not that fast ...
                        Utils.AddToViewersCol(ircMessage.Author);

                        // Add the message to the collection
                        MainWindow.colChatMessages.Add(ircMessage);

                        //MainWindow.instance.Dispatcher.BeginInvoke(new Action(delegate
                        //{
                        //    MainWindow.colChatMessages.Add(ircMessage);
                        //}));

                        //App.Current.Dispatcher.BeginInvoke(new Action(delegate
                        //{
                        //    MainWindow.colChatMessages.Add(ircMessage);
                        //}));

                        // Execute command checking and executing in a task to offload receiving
                        new Task(() =>
                        {
                            string firstWord         = Regex.Match(ircMessage.Message, @"^\S+\b").Value.ToLower();
                            UserCommand foundCommand = MainWindow.colBotCommands.FirstOrDefault(x =>
                                                                                                x.Command == firstWord);

                            if (foundCommand != null)
                            {
                                foundCommand.ExecuteCommand(ircMessage);
                            }
                            else
                            {
                                BotCommands.RunBotCommand(firstWord, ircMessage);
                            }
                        }).Start();
                        break;
                    }
                }
                else
                {
                    switch (ircMessage.Command)
                    {
                    case "PING":     // Received PING
                        ircClient.WriteLine("PONG");
                        break;

                    case "MODE":     // Received MODE
                        if (ircMessage.Args[1] == "+o")
                        {
                            // Set throttle for current user as operator
                            if (ircMessage.Args[2] == connectedUser.UserName)
                            {
                                ircClient.throttle = 350;
                            }
                        }
                        else if (ircMessage.Args[1] == "-o")
                        {
                            // Set throttle for current user as member
                            if (ircMessage.Args[2] == connectedUser.UserName)
                            {
                                ircClient.throttle = 1550;
                            }
                        }
                        break;
                    }
                }
            }
        }