Example #1
0
 private async void Client_MessageReceived(object sender, Discord.MessageEventArgs e)
 {
     if (CopiedUsers.Contains(e.User.Id))
     {
         await e.Send(e.Message.Text);
     }
 }
Example #2
0
        async private void OnMessageReceived(object sender, Discord.MessageEventArgs e)
        {
            var message = e.Message;

            if (message.Text.StartsWith(_botCommandPrefix) ||
                message.IsMentioningMe())
            {
                if (message.Text.Contains("serverstatus"))
                {
                    var data = await Module.ServerStatus.FetchServerData();

                    if (data.Version == null)
                    {
                        await e.Channel.SendMessage("Failed to retrieve server data. Currently offline, perhaps?");
                    }
                    else
                    {
                        var response = "**Server is up**; " + data.Version + ", with "
                                       + data.PlayerCount + " players on the gamemode " + "\"" + data.Mode
                                       + "\"";
                        Console.WriteLine(response);
                        await e.Channel.SendMessage(response);
                    }
                }
            }
        }
Example #3
0
 private async void Client_MessageReceived(object sender, Discord.MessageEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(e.Message.Text))
     {
         return;
     }
     if (CopiedUsers.Contains(e.User.Id))
     {
         await e.Channel.SendMessage(e.Message.Text.Replace("@everyone", "@everryone"));
     }
 }
Example #4
0
 private async void Client_MessageReceived(object sender, Discord.MessageEventArgs e)
 {
     if (e.User.Id == NadekoBot.Client.CurrentUser.Id)
     {
         return;
     }
     try {
         if (string.IsNullOrWhiteSpace(e.Message.Text))
         {
             return;
         }
         if (CopiedUsers.Contains(e.User.Id))
         {
             await e.Channel.SendMessage(e.Message.Text);
         }
     } catch { }
 }
Example #5
0
 // Fires when bot receives a message from any discord channel
 public static void onDiscordMessageReceived(object s, Discord.MessageEventArgs e)
 {
     if (e.Message.Text.Length > 0 && e.Message.Text[0] == '!')
     {
         Commands.handleDiscordCommand(new Objects.DiscordCommand(e.User.Name, e.Message.Text, e.Channel.Name, e.Channel.Id));
     }
     if (e.Channel.Name.ToLower() == "relay")
     {
         if (e.Message.Text.ToLower() == "!restart")
         {
             Common.relay("Restarting... Please standby!");
             System.Diagnostics.Process.Start(Assembly.GetExecutingAssembly().Location);
             Environment.Exit(0);
         }
     }
     Console.WriteLine(string.Format("[{0}] {1}: {2}", e.Channel.Name, e.User.Name, e.Message.Text));
 }
Example #6
0
        //Take a command and it's arguments and perform the task.
        public void ProcessCommand(string command, List <string> args, Discord.MessageEventArgs dmsg)
        {
            //Text command. Sends an SMS to a phone number using Twilio.
            if (command == "text")
            {
                string smsTo      = args.First(); args.RemoveAt(0);   //The to number should be the first argument.
                string smsMessage = string.Join(" ", args.ToArray()); //The rest of the arguments form the body of the message.

                //This first part handles the SMS if the contact is a phone number.
                float temp;
                if (float.TryParse(smsTo, out temp))
                {
                    if (isAdmin(dmsg.User))
                    {
                        com.SendFormattedSms(smsMessage, smsTo, dmsg);
                        SendMessage(dmsg.Channel, string.Format(Program.smsSent, smsTo, smsMessage));
                    }
                    else
                    {
                        SendMessage(dmsg.Channel, string.Format(Program.smsNotAllowed, dmsg.User.Name));
                    }
                }
                //Otherwise send the text to the contact if they're in the contact book.
                else
                {
                    string number = com.getNumberFromContact(smsTo);
                    smsTo = smsTo.First().ToString().ToUpper() + smsTo.Substring(1);

                    if (!string.IsNullOrEmpty(number))
                    {
                        com.SendFormattedSms(smsMessage, number, dmsg);
                        SendMessage(dmsg.Channel, string.Format(Program.smsSent, smsTo, smsMessage));
                    }
                    else
                    {
                        SendMessage(dmsg.Channel, string.Format(Program.contactNotFound, smsTo));
                    }
                }
            }
            else if (command == "setchannel")
            {
                Program.growChannel = dmsg.Channel;
                SendMessage(dmsg.Channel, "The channel has been set.");
                SendMessage(dmsg.Channel, (string.Format("The channel name is {0}", Program.growChannel.Name)));
            }
        }
Example #7
0
        public void ProcessMessage(Object user, Discord.MessageEventArgs msg)
        {
            //Incoming Discord Message.
            //If it starts with !, it's treated as a command.
            //Check the list of commands to see if the command exists.
            //The message is then split into a command and the arguments,
            //and then passed to be run as a command to ProcessCommand().

            if (msg.Message.Text.StartsWith("!"))
            {
                List <string> words   = msg.Message.Text.Split(' ').ToList();
                string        command = words.First().Trim('!');
                List <string> args    = words.ToList(); args.RemoveAt(0);

                if (Program.commands.Contains(command))
                {
                    ProcessCommand(command, args, msg);
                }
                else
                {
                    SendMessage(msg.Channel, "No such command: \"" + command + "\".");
                }
            }
        }
Example #8
0
 //Send the SMS to the number using Twilio.
 public void SendFormattedSms(string msg, string to, Discord.MessageEventArgs dmsg)
 {
     twilio.SendMessage(Program.twilioFrom, to, formatSms(dmsg, msg));
 }
Example #9
0
 //Format a string into an acceptable SMS with greeting.
 public string formatSms(Discord.MessageEventArgs dmsg, string msg)
 {
     return(string.Format(Program.smsGreeting, dmsg.User.Name, dmsg.Channel.Name, msg));
 }
Example #10
0
 public virtual void OnReceivedMessage(object sender, Discord.MessageEventArgs e)
 {
 }