// Called when a message is created on the Discord server private void Discord_MessageCreate(Message message) { // Bot-check if (message.author.bot == true) { return; } Channel.GetChannel(_client, message.channel_id, channel => { // DM-check if (channel.type != ChannelType.DM) { return; } // No code found var info = KeyInfo.FindByKey(message.content); if (info == null) { channel.CreateMessage(_client, GetMsg("Unable To Find Code")); return; } var canAuthenticate = Interface.Oxide.CallHook("CanDiscordAuthenticate", info.Player.Id, message.author.id); if (canAuthenticate is bool && !(bool)canAuthenticate) { channel.CreateMessage(_client, GetMsg("Authentication Denied By Plugin", info.Player.Id)); return; } // Already authenticated-check var data1 = PlayerData.FindByGame(info.Player.Id); var data2 = PlayerData.FindByDiscord(message.author.id); if (!_config.OverwriteData && (data1 != null || data2 != null)) { channel.CreateMessage(_client, GetMsg("Already Authenticated")); } else { if (data1 != null) { channel.CreateMessage(_client, GetMsg("In-Game Overwrite", info.Player.Id)); Interface.Oxide.CallHook("OnDiscordAuthOverwrite", data1.GameId, info.Player.Id, data1.DiscordId, message.author.id); _data.Remove(data1); } if (data2 != null) { channel.CreateMessage(_client, GetMsg("Discord Overwrite", info.Player.Id)); Interface.Oxide.CallHook("OnDiscordAuthOverwrite", data2.GameId, info.Player.Id, data2.DiscordId, message.author.id); _data.Remove(data2); } } // Adds to data file _data.Add(new PlayerData { DiscordId = message.author.id, GameId = info.Player.Id }); channel.CreateMessage(_client, GetMsg("Authenticated", info.Player.Id)); if (!string.IsNullOrEmpty(_config.AuthLogChannel)) { Channel.GetChannel(_client, _config.AuthLogChannel, logChannel => { logChannel?.CreateMessage(_client, new StringBuilder(GetMsg("Log")).Replace("{discordName}", message.author.username) .Replace("{discordId}", message.author.id).Replace("{gameId}", info.Player.Id) .Replace("{gameName}", info.Player.Name).ToString()); }); } if (!string.IsNullOrEmpty(_config.GroupConnected)) { info.Player.AddToGroup(_config.GroupConnected); } Interface.Oxide.CallHook("OnDiscordAuthenticate", info.Player.Id, message.author.id); }); }