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 = message["d"]["content"].ToString(); DiscordMember tempMember = new DiscordMember(); tempMember = foundServerChannel.members.Find(x => x.user.id == message["d"]["author"]["id"].ToString()); dmea.author = tempMember; Regex r = new Regex("\\d+"); foreach (Match mm in r.Matches(dmea.message)) { if (mm.Value == Me.user.id) { if (MentionReceived != null) { MentionReceived(this, dmea); } } } if (MessageReceived != null) { MessageReceived(this, dmea); } KeyValuePair <string, JObject> toAdd = new KeyValuePair <string, JObject>(message["d"]["id"].ToString(), message); MessageLog.Add(toAdd); } } catch (Exception ex) { Console.WriteLine("!!! {0}", ex.Message); Console.Beep(100, 1000); } }
public void DiscordChannelMessage(object s, DiscordMessageEventArgs e) { var query = Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == e.Message.Channel.Id); if (query != null) { var thisLink = FindUserLink(e.Message.Author.Username); var parsedMessage = ParseDiscordMessage(e.Message.Content, e.Message.MentionedUsers); var isAction = parsedMessage.StartsWith(DiscordMessageHelper.ActionControl) && parsedMessage.EndsWith(DiscordMessageHelper.ActionControl); if (isAction) { parsedMessage = parsedMessage.DiscordToIrcAction(); } var chunkSize = Config.IRCServer.MaxMessageSize; if (parsedMessage.Length <= chunkSize) { if (isAction) { IrcLink.SendAction(thisLink.IrcUid, parsedMessage, query.IRC); } else { IrcLink.SendMessage(thisLink.IrcUid, parsedMessage, query.IRC); } } else { for (var i = 0; i < parsedMessage.Length; i += Config.IRCServer.MaxMessageSize) { if (i + Config.IRCServer.MaxMessageSize > parsedMessage.Length) { chunkSize = parsedMessage.Length - i; } var iterationMessage = parsedMessage.Substring(i, chunkSize); if (isAction) { IrcLink.SendAction(thisLink.IrcUid, iterationMessage, query.IRC); } else { IrcLink.SendMessage(thisLink.IrcUid, iterationMessage, query.IRC); } } } foreach (var attachment in e.Message.Attachments) { IrcLink.SendMessage(thisLink.IrcUid, $"{attachment.Url}", query.IRC); } } }
public static void TestRheaStream(DiscordMessageEventArgs e) { DiscordVoiceClient vc = client.GetVoiceClient(); if (vc == null) { SendBotMessage("!@Not in a channel!", e.Channel); } try { int ms = 20;//buffer int channels = 1; int sampleRate = 48000; int blockSize = 48 * 2 * channels * ms; //sample rate * 2 * channels * milliseconds byte[] buffer = new byte[blockSize]; var outFormat = new WaveFormat(sampleRate, 16, channels); vc.SetSpeaking(true); using (var mp3Reader = new MediaFoundationReader("https://www.youtube.com/watch?v=2Vv-BfVoq4g")) { using (var resampler = new MediaFoundationResampler(mp3Reader, outFormat) { ResamplerQuality = 60 }) { int byteCount; while ((byteCount = resampler.Read(buffer, 0, blockSize)) > 0) { if (vc.Connected) { vc.SendVoice(buffer); } else { break; } } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Voice finished enqueuing"); Console.ForegroundColor = ConsoleColor.White; resampler.Dispose(); mp3Reader.Close(); } } } catch (Exception ex) { Log("Exception during voice: `" + ex.Message + "`\n\n```" + ex.StackTrace + "\n```", LogType.Console); } #endregion }
public void CommandTrigger(DiscordMessageEventArgs e) { var parts = e.MessageText.ToString().Split(null, 2); if (parts.Length == 2) { client.UpdateCurrentGame(parts[1]); e.Channel.SendMessage("thanks, on discord i'm now playing " + parts[1]); } else { e.Channel.SendMessage("playing: set my discord now playing status"); } }
/// <summary> /// Called when Discord sends us a message. /// </summary> /// <param name="o">The o.</param> /// <param name="args">The <see cref="DiscordMessageEventArgs"/> instance containing the event data.</param> private void MessageReceived(object o, DiscordMessageEventArgs args) { if (_receivedMessage != null) { foreach (IMessage message in _waitingMessages) { _receivedMessage(message); } _waitingMessages.Clear(); _receivedMessage(new Message(args)); } else { _waitingMessages.Add(new Message(args)); } }
private void ParseMessage(DiscordMessageEventArgs message) { //Clean check if (message.message.content.Length <= 1) { return; } if (!message.message.content.StartsWith(Concordia.config.CommandPrefix)) { return; } string[] stuff = message.message.content.Split(' '); string command = stuff[0].Substring(Concordia.config.CommandPrefix.Length); //get command var botCommand = CommandManager.GetCommand(command); if (botCommand != null) { DiscordUserMessage dMessage = new DiscordUserMessage(); dMessage.CommandText = message.message.content; string[] commandParams = new string[stuff.Length - 1]; for (int i = 1; i < stuff.Length; i++) { commandParams[i - 1] = stuff[i]; } dMessage.CommandParams = commandParams; dMessage.Arguments = string.Join(" ", commandParams); dMessage.Message = message; botCommand.userMessage = dMessage; RouteCommand(botCommand); } else//command is null { Concordia.client.SendMessageToChannel("Something went horribly wrong in the MessageManager.", message.message.Channel()); } }
public void AddMessageToQue(DiscordMessageEventArgs command) { _messageQ.Enqueue(command); }
public static void LogPublicMessage(object sender, DiscordMessageEventArgs e) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("[PUBMSG]{" + e.Channel.Name + "}" + e.Author.Username + ":" + e.MessageText); Console.ResetColor(); }
public static void HandlePublicMessage(object sender, DiscordMessageEventArgs e) { /*To be implemented*/ }