/// <summary> /// The function to handle received chat messages /// </summary> /// <param name="Message">The received message</param> public static void HandleCommands(String Message, DiscordSharp.Events.DiscordMessageEventArgs e) { if (!Message.StartsWith(Config.CommandString)) { return; } Message = Utils.ReplaceFirstOccurrence(Message, Config.CommandString, ""); String Command = Utils.GetWordAt(Message, 1).ToLower(); String Msg = Utils.ReplaceFirstOccurrence(Message, Command, ""); switch (Command) { case "help": CMDHelp(e, Msg); break; case "echo": CMDEcho(e, Msg); break; case "play": PlayMusic(e, Msg); break; default: CommandNotfound(e, Command, Msg); break; } }
private void MessageCreateEvents(JObject message) { try { string tempChannelID = message["d"]["channel_id"].ToString(); var foundServerChannel = ServersList.Find(x => x.channels.Find(y => y.id == tempChannelID) != null); if (foundServerChannel == null) { if (message["d"]["author"]["id"].ToString() != Me.ID) { var foundPM = PrivateChannels.Find(x => x.id == message["d"]["channel_id"].ToString()); DiscordPrivateMessageEventArgs dpmea = new DiscordPrivateMessageEventArgs(); dpmea.Channel = foundPM; dpmea.message = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(this); tempMember.Username = message["d"]["author"]["username"].ToString(); tempMember.ID = message["d"]["author"]["id"].ToString(); dpmea.author = tempMember; if (PrivateMessageReceived != null) PrivateMessageReceived(this, dpmea); } else { //if (DebugMessageReceived != null) // DebugMessageReceived(this, new DiscordDebugMessagesEventArgs { message = "Ignoring MESSAGE_CREATE for private channel for message sent from this client." }); } } else { DiscordMessageEventArgs dmea = new DiscordMessageEventArgs(); dmea.Channel = foundServerChannel.channels.Find(y => y.id == tempChannelID); dmea.message_text = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(this); tempMember = foundServerChannel.members.Find(x => x.ID == message["d"]["author"]["id"].ToString()); dmea.author = tempMember; DiscordMessage m = new DiscordMessage(); m.author = dmea.author; m.channel = dmea.Channel; m.content = dmea.message_text; m.id = message["d"]["id"].ToString(); m.RawJson = message; m.timestamp = DateTime.Now; dmea.message = m; Regex r = new Regex("\\d+"); foreach (Match mm in r.Matches(dmea.message_text)) if (mm.Value == Me.ID) if (MentionReceived != null) MentionReceived(this, dmea); KeyValuePair<string, DiscordMessage> toAdd = new KeyValuePair<string, DiscordMessage>(message["d"]["id"].ToString(), m); MessageLog.Add(toAdd); if (MessageReceived != null) MessageReceived(this, dmea); } } catch (Exception ex) { DebugLogger.Log("Error ocurred during MessageCreateEvents: " + ex.Message, MessageLevel.Error); } }
private void MessageCreateEvents(JObject message) { try { string tempChannelID = message["d"]["channel_id"].ToString(); var foundServerChannel = ServersList.Find(x => x.channels.Find(y => y.id == tempChannelID) != null); if (foundServerChannel == null) { var foundPM = PrivateChannels.Find(x => x.id == message["d"]["channel_id"].ToString()); DiscordPrivateMessageEventArgs dpmea = new DiscordPrivateMessageEventArgs(); dpmea.Channel = foundPM; dpmea.message = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(); tempMember.user.username = message["d"]["author"]["username"].ToString(); tempMember.user.id = message["d"]["author"]["id"].ToString(); dpmea.author = tempMember; if (PrivateMessageReceived != null) PrivateMessageReceived(this, dpmea); } else { DiscordMessageEventArgs dmea = new DiscordMessageEventArgs(); dmea.Channel = foundServerChannel.channels.Find(y => y.id == tempChannelID); dmea.message_text = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(); tempMember = foundServerChannel.members.Find(x => x.user.id == message["d"]["author"]["id"].ToString()); dmea.author = tempMember; DiscordMessage m = new DiscordMessage(); m.author = dmea.author; m.channel = dmea.Channel; m.content = dmea.message_text; m.id = message["d"]["id"].ToString(); m.RawJson = message; dmea.message = m; Regex r = new Regex("\\d+"); foreach (Match mm in r.Matches(dmea.message_text)) if (mm.Value == Me.user.id) if (MentionReceived != null) MentionReceived(this, dmea); if (MessageReceived != null) MessageReceived(this, dmea); KeyValuePair<string, DiscordMessage> toAdd = new KeyValuePair<string, DiscordMessage>(message["d"]["id"].ToString(), m); MessageLog.Add(toAdd); } } catch (Exception ex) { Console.WriteLine("!!! {0}", ex.Message); Console.Beep(100, 1000); } }
private void MessageCreateEvents(JObject message) { //try //{ string tempChannelID = message["d"]["channel_id"].ToString(); //DiscordServer foundServerChannel = ServersList.Find(x => x.channels.Find(y => y.id == tempChannelID) != null); DiscordChannel potentialChannel = GetDiscordChannelByID(message["d"]["channel_id"].ToString()); if (potentialChannel == null) //private message create { if (message["d"]["author"]["id"].ToString() != Me.ID) { var foundPM = PrivateChannels.Find(x => x.ID == message["d"]["channel_id"].ToString()); DiscordPrivateMessageEventArgs dpmea = new DiscordPrivateMessageEventArgs(); dpmea.Channel = foundPM; dpmea.Message = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(this); tempMember.Username = message["d"]["author"]["username"].ToString(); tempMember.ID = message["d"]["author"]["id"].ToString(); dpmea.Author = tempMember; tempMember.parentclient = this; dpmea.RawJson = message; if (PrivateMessageReceived != null) PrivateMessageReceived(this, dpmea); } else { //if (DebugMessageReceived != null) // DebugMessageReceived(this, new DiscordDebugMessagesEventArgs { message = "Ignoring MESSAGE_CREATE for private channel for message sent from this client." }); } } else { DiscordMessageEventArgs dmea = new DiscordMessageEventArgs(); dmea.RawJson = message; dmea.Channel = potentialChannel; dmea.MessageText = message["d"]["content"].ToString(); DiscordMember tempMember = null; tempMember = potentialChannel.Parent.GetMemberByKey(message["d"]["author"]["id"].ToString()); if (tempMember == null) { tempMember = JsonConvert.DeserializeObject<DiscordMember>(message["author"].ToString()); tempMember.parentclient = this; tempMember.Parent = potentialChannel.Parent; potentialChannel.Parent.AddMember(tempMember); } dmea.Author = tempMember; DiscordMessage m = new DiscordMessage(); m.Author = dmea.Author; m.channel = dmea.Channel; m.TypeOfChannelObject = dmea.Channel.GetType(); m.Content = dmea.MessageText; m.ID = message["d"]["id"].ToString(); m.RawJson = message; m.timestamp = DateTime.Now; dmea.Message = m; if (!message["d"]["attachments"].IsNullOrEmpty()) { List<DiscordAttachment> tempList = new List<DiscordAttachment>(); foreach (var attachment in message["d"]["attachments"]) { tempList.Add(JsonConvert.DeserializeObject<DiscordAttachment>(attachment.ToString())); } m.Attachments = tempList.ToArray(); } if (!message["d"]["mentions"].IsNullOrEmpty()) { JArray mentionsAsArray = JArray.Parse(message["d"]["mentions"].ToString()); foreach (var mention in mentionsAsArray) { string id = mention["id"].ToString(); if (id.Equals(Me.ID)) { if (MentionReceived != null) MentionReceived(this, dmea); } } } KeyValuePair<string, DiscordMessage> toAdd = new KeyValuePair<string, DiscordMessage>(message["d"]["id"].ToString(), m); MessageLog.Add(message["d"]["id"].ToString(), m); if (MessageReceived != null) MessageReceived(this, dmea); } //} //catch (Exception ex) //{ // DebugLogger.Log("Error ocurred during MessageCreateEvents: " + ex.Message, MessageLevel.Error); //} }
public static void PlayMusic(DiscordSharp.Events.DiscordMessageEventArgs e, String message) { TestRheaStream(e); client.DeleteMessage(e.Message.ID); }
public static void CMDEcho(DiscordSharp.Events.DiscordMessageEventArgs e, String message) { SendBotMessage(Utils.Replace(Utils.Replace(Messages.EchoReply, "~2", message), "~1", MentoinUser(e.Message.Author)), e.Message.Channel()); client.DeleteMessage(e.Message.ID); }
public static void CommandNotfound(DiscordSharp.Events.DiscordMessageEventArgs e, String Command, String message) { SendBotMessage(Utils.Replace(Messages.CommandNotFound, "~1", Command), e.Message.Channel()); }