public async Task GetProfileAsync([Remainder] string target) { RavenGuild guild = RavenDb.GetGuild(Context.Guild.Id); Regex regex = new Regex(@"<@([0-9]*)>"); Match match = regex.Match(target); if (match.Success) { // See if what they gave was a real person ulong.TryParse(match.Groups[1].Value, out ulong id); if (id is 0) { await ReplyAsync("Invalid User Mentioned."); return; } RavenUser mentionedUser = guild.GetUser(id); if (mentionedUser is null) { await ReplyAsync("The user specified doesn't exist within the system."); return; } // Gotem. await ReplyAsync(null, false, DiscordEvents.GetUserProfile(id, guild)); } else { RavenUser user = guild.Users.FirstOrDefault(x => x.Username.StartsWith(target)); if (user is null) { await ReplyAsync("Couldn't find anyone who's name was at all like that. To be fair, it's not a very indepth search."); return; } await ReplyAsync(null, false, DiscordEvents.GetUserProfile(user.UserId, guild)); } }
/// <summary>Called when a user joins the server. </summary> internal async Task GuildUserJoinAsync(SocketGuildUser user) { foreach (PluginInfo plugin in GlobalConfig.PluginInfo) { if (plugin.MessageReceivedAsync != null) { if (GlobalConfig.RunPluginFunctionsAsynchronously) #pragma warning disable 4014 { plugin.GuildUserLeave.Invoke(user); } #pragma warning restore 4014 else { await plugin.GuildUserLeave(user); } } } // Add it to the global database if they don't exist if (RavenDb.GetUser(user.Id) is null) { RavenDb.CreateNewUser(user.Id, user.Username, user.DiscriminatorValue, user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl()); } // Get the guild this user is in RavenGuild guild = RavenDb.GetGuild(user.Guild.Id) ?? RavenDb.CreateNewGuild(user.Guild.Id, user.Guild.Name); // Update the total amount of users guild.TotalUsers = (uint)user.Guild.Users.Count; // If they rejoined, we'll store their old name to log bool rejoined = false; string username = string.Empty; // Get the user from that guild RavenUser guildUser = guild.GetUser(user.Id); if (guildUser is null) // if they don't exist, we'll need to create them { guild.CreateNewUser(user.Id, user.Username, user.DiscriminatorValue, user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl()); } else { // They rejoined, update their name in case/discrim in case it changed rejoined = true; username = guildUser.Username + "#" + guildUser.Discriminator; guildUser.Username = user.Username; guildUser.Discriminator = user.DiscriminatorValue; guild.Save(); // Save the updated information, while storing the old one for logging purposes } // Process welcome message if one is set if (guild.GuildSettings.WelcomeMessage.Enabled) { // If the targeted channel is null or no longer exists or the message itself is undefined if (guild.GuildSettings.WelcomeMessage.ChannelId is null || user.Guild.GetTextChannel(guild.GuildSettings.WelcomeMessage.ChannelId.GetValueOrDefault()) is null || string.IsNullOrWhiteSpace(guild.GuildSettings.WelcomeMessage.Message)) { // If the logging channel is setup, exists, and is enabled if (!(guild.LoggingSettings.ChannelId is null) && !(user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.GetValueOrDefault()) is null) && guild.LoggingSettings.Enabled) { // Log to the logging channel if it has been set await user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.Value).SendMessageAsync(null, false, new EmbedBuilder() { Title = "Warning!", Color = new Color(255, 128, 0), // Orange Description = "Unable to send welcome message. Channel or message are currently null. Please reconfigure it.", Footer = new EmbedFooterBuilder() { Text = $"{DateTime.UtcNow:ddd MMM d yyyy HH mm}" } }.Build()); } } else { // Send the welcome message and repalce the server or user tags if they are present await user.Guild.GetTextChannel(guild.GuildSettings.WelcomeMessage.ChannelId.Value) .SendMessageAsync(guild.GuildSettings.WelcomeMessage.Message .Replace("%SERVER%", user.Guild.Name) .Replace("%USER%", user.Username)); } }