예제 #1
0
 private void Unload()
 {
     if (_pluginConfig.DiscordToServer)
     {
         DiscordCore?.Call("UnsubscribeChannel", _pluginConfig.ChatChannel, this);
     }
 }
예제 #2
0
        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;
        }
예제 #3
0
        private void SendChatToChannel(string channel, string message)
        {
            if (string.IsNullOrEmpty(channel))
            {
                return;
            }

            DiscordCore.Call("SendMessageToChannel", channel, message);
        }
예제 #4
0
        private void OnChannelSubscribed(Channel channel, Plugin plugin)
        {
            if (this != plugin)
            {
                return;
            }

            DiscordCore.Call("GetChannelMessages", channel.id, GetMessagesKey);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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++;
                }
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
 private void SendMessageToUser(string id, string message)
 {
     DiscordCore.Call("SendMessageToUser", id, message);
 }