private static Task Discord_AllianceMessage(DSharpPlus.EventArgs.MessageCreateEventArgs e) { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord", "Got a message " + e.Message.ChannelId + " " + e.Channel.Id, Color.Blue, (long)player.Id.SteamId); } } if (allianceChannels.ContainsKey(e.Channel.Id)) { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord 1", "Is an alliance channel " + e.Message.ChannelId + " " + e.Channel.Id, Color.Blue, (long)player.Id.SteamId); } } if (e.Author.IsBot) { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord 2", "Bot message " + e.Message.ChannelId + " " + e.Channel.Id, Color.Blue, (long)player.Id.SteamId); } } //if (LastMessageSent.ContainsKey(allianceChannels[e.Channel.Id])) //{ // if (LastMessageSent[allianceChannels[e.Channel.Id]].Equals(e.Message.Content)) // { // return Task.CompletedTask; // } //} String[] split = e.Message.Content.Split(':'); int i = 0; if (WorldName.Equals("") && MyMultiplayer.Static.HostName != null) { if (MyMultiplayer.Static.HostName.Contains("SENDS")) { WorldName = MyMultiplayer.Static.HostName.Replace("SENDS", ""); } else { if (MyMultiplayer.Static.HostName.Equals("Sigma Draconis Lobby")) { WorldName = "01"; } else { WorldName = MyMultiplayer.Static.HostName; } } } String exclusionBeforeFormat = GetStringBetweenCharacters(split[0], '[', ']'); if (!exclusionBeforeFormat.Contains(WorldName)) { StringBuilder message = new StringBuilder(); foreach (String s in split) { if (i == 0) { i++; continue; } message.Append(s); } StringBuilder newMessage = new StringBuilder(); string output = e.Message.Content.Substring(e.Message.Content.IndexOf(':') + 1); AllianceChat.SendChatMessageFromDiscord(allianceChannels[e.Channel.Id], split[0].Replace("**", ""), output.Replace("**", "").Trim(), 0); } } else { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord 3", "Player message " + e.Message.ChannelId + " " + e.Channel.Id, Color.Blue, (long)player.Id.SteamId); } } if (WorldName.Equals("") && MyMultiplayer.Static.HostName != null) { if (MyMultiplayer.Static.HostName.Contains("SENDS")) { WorldName = MyMultiplayer.Static.HostName.Replace("SENDS", ""); } else { if (MyMultiplayer.Static.HostName.Equals("Sigma Draconis Lobby")) { WorldName = "01"; } else { WorldName = MyMultiplayer.Static.HostName; } } } if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord 4", "Player message 1", Color.Blue, (long)player.Id.SteamId); } } //if (nickNames.ContainsKey(e.Message.Author.Id)) //{ // if (debugMode) // { // if (MySession.Static.Players.GetPlayerByName("Crunch") != null) // { // MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); // ShipyardCommands.SendMessage("Discord 5", "Player message 2", Color.Blue, (long)player.Id.SteamId); // } // } AllianceChat.SendChatMessageFromDiscord(allianceChannels[e.Channel.Id], "[D] " + e.Message.Author.Username, e.Message.Content.Trim(), e.Author.Id); //} //else //{ // if (debugMode) // { // if (MySession.Static.Players.GetPlayerByName("Crunch") != null) // { // MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); // ShipyardCommands.SendMessage("Discord 6", "Player message 3", Color.Blue, (long)player.Id.SteamId); // } // } // Task.Run(async () => // { // String nick; // DiscordMember mem = await e.Guild.GetMemberAsync(e.Author.Id); // nick = mem.Nickname; // if (String.IsNullOrEmpty(nick)) // { // nickNames.Add(e.Message.Author.Id, mem.DisplayName); // } // else // { // nickNames.Add(e.Message.Author.Id, nick); // } // AllianceChat.SendChatMessageFromDiscord(allianceChannels[e.Channel.Id], "[D] " + nickNames[e.Message.Author.Id], e.Message.Content.Trim(), e.Author.Id); // }); //} //e.Message.Author. //String nick = e.Guild.GetMemberAsync(e.Author.Id).Result.Nickname; //if (String.IsNullOrEmpty(nick)) //{ //} //else //{ // AllianceChat.SendChatMessageFromDiscord(allianceChannels[e.Channel.Id], "[D] " + nick, e.Message.Content.Trim(), e.Author.Id); //} } } else { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord 3", "Message channel not alliance channel " + e.Message.ChannelId + " " + e.Channel.Id, Color.Blue, (long)player.Id.SteamId); } } } return(Task.CompletedTask); }
public static void SendAllianceMessage(Alliance alliance, string prefix, string message) { if (AllianceHasBot(alliance.AllianceId) && alliance.DiscordChannelId > 0) { DiscordClient bot = allianceBots[alliance.AllianceId]; DiscordChannel chann = bot.GetChannelAsync(alliance.DiscordChannelId).Result; if (bot == null) { return; } if (WorldName.Equals("") && MyMultiplayer.Static.HostName != null) { if (MyMultiplayer.Static.HostName.Contains("SENDS")) { WorldName = MyMultiplayer.Static.HostName.Replace("SENDS", ""); } else { if (MyMultiplayer.Static.HostName.Equals("Sigma Draconis Lobby")) { WorldName = "01"; } else { WorldName = MyMultiplayer.Static.HostName; } } } try { botId = bot.SendMessageAsync(chann, "**[" + WorldName + "] " + prefix + "**: " + message.Replace(" /n", "\n")).Result.Author.Id; } catch (DSharpPlus.Exceptions.RateLimitException) { if (attempt <= 5) { attempt++; SendAllianceMessage(alliance, prefix, message); attempt = 0; } else { attempt = 0; } } catch (System.Net.Http.HttpRequestException) { AllianceChat.SendChatMessageFromDiscord(alliance.AllianceId, "Bot", "Failed to send message.", 0); } catch (Exception ex) { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord", "" + ex.ToString(), Color.Blue, (long)player.Id.SteamId); } } } } else { if (debugMode) { if (MySession.Static.Players.GetPlayerByName("Crunch") != null) { MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch"); ShipyardCommands.SendMessage("Discord", "doesnt have bot or channel id is 0", Color.Blue, (long)player.Id.SteamId); } } } }