private void Unload() { if (_pluginConfig.DiscordToServer) { DiscordCore?.Call("UnsubscribeChannel", _pluginConfig.ChatChannel, this); } }
private void OnDiscordCoreReady() { if (!(DiscordCore?.Call <bool>("IsReady") ?? false)) { return; } if (_pluginConfig.DiscordToServer && !string.IsNullOrEmpty(_pluginConfig.ChatChannel)) { DiscordCore.Call("SubscribeChannel", _pluginConfig.ChatChannel, this, new Func <Message, object>(HandleMessage)); } _bot = DiscordCore.Call <DiscordUser>("GetBot"); if (!_storedData.BotIds.Contains(_bot.id)) { _storedData.BotIds.Add(_bot.id); SaveData(); } if (_pluginConfig.PluginSupport.AdminChat.Enabled) { DiscordCore.Call("SubscribeChannel", _pluginConfig.PluginSupport.AdminChat.ChatChannel, this, new Func <Message, object>(HandleAdminChatMessage)); } _init = true; }
private void SendChatToChannel(string channel, string message) { if (string.IsNullOrEmpty(channel)) { return; } DiscordCore.Call("SendMessageToChannel", channel, message); }
private void OnChannelSubscribed(Channel channel, Plugin plugin) { if (this != plugin) { return; } DiscordCore.Call("GetChannelMessages", channel.id, GetMessagesKey); }
public DiscordBot() { using (StreamReader r = new StreamReader("./client_secret.txt")) { client_id = r.ReadToEnd(); client_id = client_id.Trim(); } discord = new DiscordCore(client_id, null); }
private object HandleMessage(Message message) { if (!_pluginConfig.DiscordToServer) { return(null); } if (ShouldIgnoreUser(message.author)) { return(null); } if (_pluginConfig.IgnoredCommands.Any(c => message.content.StartsWith(c, StringComparison.OrdinalIgnoreCase))) { return(null); } if (message.author.id == _bot.id) { return(null); } string playerId = DiscordCore.Call <string>("GetSteamIdFromDiscordId", message.author.id); if (playerId == null) { SendMessageToUser(message.author.id, Lang(LangKeys.NotLinked)); } else { IPlayer player = covalence.Players.FindPlayer(playerId); if (player == null) { PrintError($"{playerId} is linked in DiscordCore but does not exist in covalence player list"); return(null); } //Attempt to fix random mass disconnect issues NextTick(() => { BroadcastChat(player, FilterText(message.content)); }); } if (_pluginConfig.UseBotMessageDisplay) { timer.In(.25f, () => { DiscordCore.Call("DeleteMessage", message); }); } return(null); }
private void OnGetChannelMessages(List <Message> messages, string responseKey) { if (responseKey != GetMessagesKey) { return; } if (_pluginConfig.UseBotMessageDisplay) { int i = 0; foreach (Message message in messages.Where(m => !ShouldIgnoreUser(m.author) && !_storedData.BotIds.Contains(m.author.id))) { timer.In(i, () => { DiscordCore.Call("DeleteMessage", message); }); i++; } } }
private object HandleAdminChatMessage(Message message) { if (_pluginConfig.IgnoredCommands.Any(c => message.content.StartsWith(c, StringComparison.OrdinalIgnoreCase))) { return(null); } string playerId = DiscordCore.Call <string>("GetSteamIdFromDiscordId", message.author.id); if (playerId == null) { SendMessageToUser(message.author.id, Lang(LangKeys.NotLinked)); } else { IPlayer player = covalence.Players.FindPlayer(playerId); HandleAdminChat(player, message.content, MessageSource.Discord); } timer.In(.25f, () => { DiscordCore.Call("DeleteMessage", message); }); return(null); }
private void SendMessageToUser(string id, string message) { DiscordCore.Call("SendMessageToUser", id, message); }