public async Task <RuntimeResult> ChangeGuildIconAsync(Uri url = null) { if (url == null) { await ReplyAsync("", embed : EmbedHelper.FromInfo("New icon", "Please upload your new server icon.").Build()).ConfigureAwait(false); var response = await InteractiveService.NextMessageAsync(Context, timeout : TimeSpan.FromMinutes(5)).ConfigureAwait(false); if (response == null) { return(CommandRuntimeResult.FromError("You did not upload your picture in time.")); } if (!Uri.TryCreate(response.Content, UriKind.RelativeOrAbsolute, out url)) { var attachment = response.Attachments.FirstOrDefault(); if (attachment?.Height != null) { url = new Uri(response.Attachments.FirstOrDefault().Url); } else { return(CommandRuntimeResult.FromError("You did not upload any valid pictures.")); } } } using (var image = await WebHelper.GetFileStreamAsync(HttpClient, url).ConfigureAwait(false)) { // ReSharper disable once AccessToDisposedClosure await Context.Guild.ModifyAsync(x => x.Icon = new Image(image)).ConfigureAwait(false); } return(CommandRuntimeResult.FromSuccess("The server icon has been changed!")); }
public async Task <RuntimeResult> EightBallAsync([Remainder] string input) { int responseCount = Config.Commands.EightBallResponses.Count; if (responseCount == 0) // This should hopefully never happen. { return(CommandRuntimeResult.FromError( "The 8ball responses are not yet set, contact the bot developers.")); } string response = Config.Commands.EightBallResponses[Random.Next(0, responseCount)]; var embed = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = "The Magic 8Ball", IconUrl = Context.Client.CurrentUser.GetAvatarUrlOrDefault() }, Color = ColorHelper.GetRandomColor(), ThumbnailUrl = Config.Icons.EightBall } .AddField("You asked...", input) .AddField("The 8 ball says...", response); await ReplyAsync("", embed : embed.Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> GetWeatherForLocationAsync([Summary("User")] SocketUser user = null) { var targetUser = user ?? Context.User; var record = UserRepository.GetCoordinates(targetUser); if (record == null) { return(CommandRuntimeResult.FromError( "Location is not set yet! Please set the location first!")); } var geocodeResults = await Geocoder.ReverseGeocodeAsync(record.Latitude, record.Longitude).ConfigureAwait(false); var geocode = geocodeResults.FirstOrDefault(); if (geocode == null) { return(CommandRuntimeResult.FromError( "I could not find the set location! Try setting another location.")); } var forecast = await DarkSkyService.GetForecast( geocode.Coordinates.Latitude, geocode.Coordinates.Longitude, _darkSkyParams ).ConfigureAwait(false); var embeds = await Weather.GetWeatherEmbedsAsync(forecast, geocode).ConfigureAwait(false); await ReplyAsync("", embed : embeds.WeatherResults.FirstOrDefault().Build()).ConfigureAwait(false); foreach (var alert in embeds.Alerts) { await ReplyAsync("", embed : alert.Build()).ConfigureAwait(false); } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> GetWeatherForLocationAsync([Summary("Location")][Remainder] string location) { var geocodeResults = await Geocoder.GeocodeAsync(location).ConfigureAwait(false); var geocode = geocodeResults.FirstOrDefault(); if (geocode == null) { return(CommandRuntimeResult.FromError($"I could not find {location}! Try another location.")); } var forecast = await DarkSkyService.GetForecast( geocode.Coordinates.Latitude, geocode.Coordinates.Longitude, _darkSkyParams).ConfigureAwait(false); var embeds = await Weather.GetWeatherEmbedsAsync(forecast, geocode).ConfigureAwait(false); await ReplyAsync("", embed : embeds.WeatherResults.FirstOrDefault().Build()).ConfigureAwait(false); foreach (var alert in embeds.Alerts) { await ReplyAsync("", embed : alert.Build()).ConfigureAwait(false); } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> LiquifyAsync() { var message = (await Context.Channel.GetMessagesAsync().FlattenAsync().ConfigureAwait(false))? .FirstOrDefault(x => x.Attachments.Any(a => a.Width.HasValue)); if (message == null) { return(CommandRuntimeResult.FromError("No images found!")); } foreach (var attachment in message.Attachments) { using (var attachmentStream = await WebHelper.GetFileStreamAsync(HttpClient, new Uri(attachment.Url)).ConfigureAwait(false)) using (var image = new MagickImage(attachmentStream)) using (var imageStream = new MemoryStream()) { image.LiquidRescale(Convert.ToInt32(image.Width * 0.5), Convert.ToInt32(image.Height * 0.5)); image.LiquidRescale(Convert.ToInt32(image.Width * 1.5), Convert.ToInt32(image.Height * 1.5)); image.Write(imageStream, MagickFormat.Png); imageStream.Seek(0, SeekOrigin.Begin); await Context.Channel.SendFileAsync(imageStream, "liquify.png").ConfigureAwait(false); } } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> AngeryAsync() { var message = (await Context.Channel.GetMessagesAsync().FlattenAsync().ConfigureAwait(false))? .FirstOrDefault(x => x.Attachments.Any(a => a.Width.HasValue)); if (message == null) { return(CommandRuntimeResult.FromError("No images found!")); } foreach (var attachment in message.Attachments) { using (var attachmentStream = await WebHelper.GetFileStreamAsync(HttpClient, new Uri(attachment.Url)).ConfigureAwait(false)) using (var image = Image.Load(attachmentStream)) using (var imageStream = new MemoryStream()) { image.DrawPolygon(Rgba32.Red, 1000000, new PointF[] { new Point(0, 0), new Point(image.Width, image.Height) }, new GraphicsOptions { BlenderMode = PixelBlenderMode.Screen, BlendPercentage = 25 }) .SaveAsPng(imageStream); imageStream.Seek(0, SeekOrigin.Begin); await Context.Channel.SendFileAsync(imageStream, "angery.png").ConfigureAwait(false); } } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> NeedsMoreJpegAsync() { var message = (await Context.Channel.GetMessagesAsync().FlattenAsync().ConfigureAwait(false))? .FirstOrDefault(x => x.Attachments.Any(a => a.Width.HasValue)); if (message == null) { return(CommandRuntimeResult.FromError("No images found!")); } foreach (var attachment in message.Attachments) { using (var attachmentStream = await WebHelper.GetFileStreamAsync(HttpClient, new Uri(attachment.Url)).ConfigureAwait(false)) using (var image = Image.Load(attachmentStream)) using (var imageStream = new MemoryStream()) { image.SaveAsJpeg(imageStream, new JpegEncoder { Quality = 2 }); imageStream.Seek(0, SeekOrigin.Begin); await Context.Channel.SendFileAsync(imageStream, "needsmorejpeg.jpeg").ConfigureAwait(false); } } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> ThinkingAsync() { using (var response = await HttpClient.GetAsync("https://www.reddit.com/r/Thinking/.json").ConfigureAwait(false)) { if (!response.IsSuccessStatusCode) { return(CommandRuntimeResult.FromError("Reddit is out of reach, please try again later!")); } var result = JsonConvert.DeserializeObject <RedditResponseModel>(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); var children = (Context.Channel as SocketTextChannel).IsNsfw ? result.Data.Children : result.Data.Children.Where(x => !x.Data.IsNsfw).ToList(); int index = Random.Next(children.Count); var post = children[index]; string title = Config.Commands.ThinkingTitles[Random.Next(Config.Commands.ThinkingTitles.Count)]; var builder = new EmbedBuilder { Title = post.Data.Title, Description = $"{(post.Data.IsNsfw ? $"{title} (NSFW)" : title)}\n\nPosted by u/{post.Data.Author}", Url = "https://www.reddit.com/" + post.Data.Permalink, Color = ColorHelper.GetRandomColor(), ThumbnailUrl = post.Data.Url }; await ReplyAsync("", embed : builder.Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); } }
public async Task <RuntimeResult> ListRemindersAsync() { var entries = UserRepository.GetReminders(Context.User) .OrderBy(x => x.Time); if (!entries.Any()) { return(CommandRuntimeResult.FromError("You do not have a reminder set yet!")); } var sb = new StringBuilder(); var embed = ReminderService.GetReminderEmbed(""); var userTimeOffset = GetUserTimeOffset(Context.User); if (userTimeOffset > TimeSpan.Zero) { embed.WithFooter(x => x.Text = $"Converted to {Context.User.GetFullnameOrDefault()}'s timezone."); } foreach (var entry in entries) { var time = entry.Time.ToOffset(userTimeOffset); sb.AppendLine($"**{time} ({entry.Time.Humanize()})**"); string channelname = Context.Guild.GetChannel(entry.ChannelId)?.Name ?? "Unknown Channel"; sb.AppendLine($@" '{entry.Content}' at #{channelname}"); sb.AppendLine(); } await ReplyAsync("", embed : embed.WithDescription(sb.ToString()).Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public Task <RuntimeResult> CheckRiotAsync(SocketUser user = null) { var targetUser = user ?? Context.User; var record = UserRepository.GetGame(targetUser); return(Task.FromResult <RuntimeResult>(record?.RiotId == null ? CommandRuntimeResult.FromError("User hasn't setup their Riot Id yet!") : CommandRuntimeResult.FromInfo( $"{targetUser.Mention}'s Riot Id: {Format.Bold(record.RiotId)}"))); }
public Task <RuntimeResult> CheckFriendCodeAsync(SocketUser user = null) { var targetUser = user ?? Context.User; var record = UserRepository.GetGame(targetUser); return(Task.FromResult <RuntimeResult>(record?.NintendoFriendCode == null ? CommandRuntimeResult.FromError("User hasn't setup their Nintendo Friend Code yet!") : CommandRuntimeResult.FromInfo( $"{targetUser.Mention}'s Nintendo Friend Code: {Format.Bold(record.NintendoFriendCode)}"))); }
public async Task <RuntimeResult> SearchAsync([Remainder] string query) { var embedQuery = await GoogleService.SearchAsync(query).ConfigureAwait(false); if (embedQuery == null) { return(CommandRuntimeResult.FromError("I could not get the search result for now, try again later.")); } await ReplyAsync("", embed : embedQuery).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> LocationRemoveAsync() { var record = UserSettings.GetCoordinates(Context.User); if (record == null) { return(CommandRuntimeResult.FromError("You do not have a location set up yet!")); } await UserSettings.RemoveCoordinatesAsync(Context.User).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess("You have successfully removed your location!")); }
public async Task <RuntimeResult> DisableWelcomeAsync() { var record = await CoreRepository.GetOrCreateGreetingsAsync(Context.Guild).ConfigureAwait(false); if (!record.IsJoinEnabled) { return(CommandRuntimeResult.FromError("The welcome message is already disabled!")); } record.IsJoinEnabled = false; await CoreRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess("Successfully disabled the welcome message!")); }
public async Task <RuntimeResult> CleanAttachmentsAsync(int amount = 25) { var messages = (await GetMessageAsync(amount).ConfigureAwait(false)).Where(x => x.Attachments.Count > 0).ToList(); if (messages.Count == 0) { return(CommandRuntimeResult.FromError(MessagesNotFound)); } await DeleteMessagesAsync(messages).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $"Deleted {Format.Bold(messages.Count.ToString())} message(s) containing attachments!")); }
public async Task <RuntimeResult> CleanUserAsync(SocketUser user, int amount = 25) { var messages = (await GetMessageAsync(amount).ConfigureAwait(false)).Where(x => x.Author.Id == user.Id).ToList(); if (messages.Count == 0) { return(CommandRuntimeResult.FromError(MessagesNotFound)); } await DeleteMessagesAsync(messages).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $"Deleted {Format.Bold(messages.Count.ToString())} message(s) from user {Format.Bold(user.Mention)}!")); }
public async Task <RuntimeResult> ConfigMessageAsync([Remainder] string message) { var record = await CoreRepository.GetOrCreateGreetingsAsync(Context.Guild).ConfigureAwait(false); if (message.Length > 1024) { return(CommandRuntimeResult.FromError("Your welcome message is too long!")); } record.WelcomeMessage = message; await CoreRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess($"Welcome message set to: {Format.Bold(message)}")); }
public async Task <RuntimeResult> SetSummaryAsync([Remainder] string summary) { if (summary.Length > 500) { return(CommandRuntimeResult.FromError("Your summary needs to be shorter than 500 characters!")); } var record = await UserRepository.GetOrCreateProfileAsync(Context.User).ConfigureAwait(false); record.Summary = summary; await UserRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess($"Successfully set summary to {Format.Bold(summary)}")); }
public async Task <RuntimeResult> CleanContainsAsync(string text, int amount = 25) { var messages = (await GetMessageAsync(amount).ConfigureAwait(false)).Where(x => x.Content.ContainsCaseInsensitive(text)) .ToList(); if (messages.Count == 0) { return(CommandRuntimeResult.FromError(MessagesNotFound)); } await DeleteMessagesAsync(messages).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $"Deleted {Format.Bold(messages.Count.ToString())} message(s) containing {text}!")); }
public async Task <RuntimeResult> GetOrCreateInviteAsync() { if (Context.Channel is INestedChannel channel) { var record = await CoreRepository.GetOrCreateGuildSettingsAsync(Context.Guild).ConfigureAwait(false); if (!record.IsInviteAllowed) { return(CommandRuntimeResult.FromError("The admin has disabled this command.")); } var invite = await channel.GetLastInviteAsync(true).ConfigureAwait(false); await ReplyAsync(invite.Url).ConfigureAwait(false); } return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> LocationSetAsync([Remainder] string location) { var geocodeResults = (await Geocoding.GeocodeAsync(location).ConfigureAwait(false)).ToList(); if (!geocodeResults.Any()) { return(CommandRuntimeResult.FromError("No results found.")); } var result = geocodeResults.FirstOrDefault(); await UserSettings.AddOrUpdateCoordinatesAsync(Context.User, result.Coordinates.Longitude, result.Coordinates.Latitude).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess($"Your location has been set to {result.FormattedAddress}!")); }
public async Task <RuntimeResult> RemoveRemindAsync() { var entry = UserRepository.GetReminders(Context.User) .OrderBy(x => x.Time) .FirstOrDefault(); if (entry == null) { return(CommandRuntimeResult.FromError("You do not have a reminder set yet!")); } await UserRepository.RemoveReminderAsync(entry).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $@"Removed the reminder ""{entry.Content}"" that was planned at {entry.Time}.")); }
public async Task <RuntimeResult> EnableWelcomeAsync() { var greetingSettings = await CoreRepository.GetOrCreateGreetingsAsync(Context.Guild).ConfigureAwait(false); var guildSettings = await CoreRepository.GetOrCreateGuildSettingsAsync(Context.Guild).ConfigureAwait(false); if (greetingSettings.IsJoinEnabled) { return(CommandRuntimeResult.FromError("The welcome message is already enabled!")); } greetingSettings.IsJoinEnabled = true; await CoreRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $"Successfully enabled the welcome message! If you haven't configure the welcome message by using `{guildSettings.CommandPrefix}server welcome message`")); }
public async Task <RuntimeResult> SnoozeReminderAsync( [Summary("Time")] TimeSpan dateTimeParsed) { var entry = UserRepository.GetReminders(Context.User) .OrderBy(x => x.Time) .FirstOrDefault(); if (entry == null) { return(CommandRuntimeResult.FromError("You do not have a reminder set yet!")); } entry.Time = entry.Time.Add(dateTimeParsed); await UserRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess( $"Your next reminder '{entry.Content}' has been delayed for {dateTimeParsed.Humanize()}!")); }
public async Task <RuntimeResult> SetLogChannelAsync(SocketTextChannel channel = null) { var record = await CoreRepository.GetOrCreateActivityAsync(Context.Guild).ConfigureAwait(false); if (channel == null) { var targetChannel = Context.Guild.GetTextChannel(record.LogChannel); return(targetChannel == null ? CommandRuntimeResult.FromError("You have not set up a valid log channel yet!") : CommandRuntimeResult.FromInfo($"The current log channel is: {Format.Bold(targetChannel.Name)}")); } if (record.LogChannel == channel.Id) { return(CommandRuntimeResult.FromInfo("The current log channel is already the specified channel!")); } record.LogChannel = channel.Id; await CoreRepository.SaveRepositoryAsync().ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess($"The current log channel has been set to {Format.Bold(channel.Name)}!")); }
public async Task <RuntimeResult> AvatarConfigureAsync() { await ReplyAsync("", embed : EmbedHelper.FromInfo(description : "Please upload the new avatar.").Build()).ConfigureAwait(false); var message = await InteractiveService.NextMessageAsync(Context, new EnsureFromUserCriterion(Context.User.Id), TimeSpan.FromMinutes(5)).ConfigureAwait(false); Uri imageUri = null; if (!string.IsNullOrEmpty(message.Content)) { var image = await WebHelper.GetImageUriAsync(HttpClient, message.Content).ConfigureAwait(false); if (image != null) { imageUri = image; } } var attachment = message.Attachments.FirstOrDefault(); if (attachment?.Height != null) { Uri.TryCreate(attachment.Url, UriKind.RelativeOrAbsolute, out imageUri); } if (imageUri == null) { return(CommandRuntimeResult.FromError("No valid images were detected.")); } var imageStream = await WebHelper.GetFileStreamAsync(HttpClient, imageUri).ConfigureAwait(false); try { // ReSharper disable once AccessToDisposedClosure await Context.Client.CurrentUser.ModifyAsync(x => x.Avatar = new Image(imageStream)).ConfigureAwait(false); } finally { imageStream.Dispose(); } return(CommandRuntimeResult.FromSuccess("Successfully changed avatar.")); }
private async Task <RuntimeResult> RemindAsync(SocketUser user, DateTimeOffset dateTime, string remindContent) { if (DateTimeOffset.Now > dateTime) { return(CommandRuntimeResult.FromError($"{dateTime} has already passed!")); } var userTimeOffset = GetUserTimeOffset(user); await ReminderService.AddReminderAsync(user, Context.Channel, dateTime, remindContent).ConfigureAwait(false); await ReplyAsync(string.Empty, embed : EmbedHelper.FromSuccess() .WithAuthor(new EmbedAuthorBuilder { IconUrl = Context.Client.CurrentUser.GetAvatarUrlOrDefault(), Name = "New Reminder Set!" }) .AddField("Reminder", remindContent, true) .AddField("At", dateTime.ToOffset(userTimeOffset)).Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> CheckSteamAsync(SocketUser user = null) { var targetUser = user ?? Context.User; var record = UserRepository.GetGame(targetUser); if (record == null || record.SteamId == 0) { return(CommandRuntimeResult.FromError("User hasn't setup their steam profile yet!")); } var profile = await SteamService.GetProfileAsync(record.SteamId).ConfigureAwait(false); var builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = profile.CustomURL ?? profile.SteamID.ToString(), IconUrl = profile.Avatar.AbsoluteUri }, Description = profile.Summary, Footer = new EmbedFooterBuilder { Text = $"Recently Played: {string.Join(", ", profile.MostPlayedGames.Select(x => x.Name))}" }, Color = ColorHelper.GetRandomColor() } .AddField("State:", profile.StateMessage, true) .AddField("Member Since:", profile.MemberSince, true) .AddField("Location:", string.IsNullOrWhiteSpace(profile.Location) ? "Not Specified." : profile.Location, true) .AddField("Real Name:", string.IsNullOrWhiteSpace(profile.RealName) ? "Not Specified." : profile.RealName, true) .AddField("VAC Banned?:", profile.IsVacBanned ? "Yes." : "No.", true); await ReplyAsync("", embed : builder.Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> LocationLookupAsync([Remainder] string location) { var geocodeResults = (await Geocoding.GeocodeAsync(location).ConfigureAwait(false)).ToList(); if (!geocodeResults.Any()) { return(CommandRuntimeResult.FromError("No results found.")); } var embed = EmbedHelper.FromInfo(); foreach (var geocodeResult in geocodeResults) { if (embed.Fields.Count > 10) { break; } embed.AddField(geocodeResult.FormattedAddress, geocodeResult.Coordinates); } await ReplyAsync("", embed : embed.Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }
public async Task <RuntimeResult> ChooseAsync([Remainder] string input) { var regexParsed = Regex.Split(input, "or|;|,|and", RegexOptions.IgnoreCase); if (regexParsed.Length == 0) { return(CommandRuntimeResult.FromError("You need to supply more than one option!")); } var embed = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = "I think you should choose...", IconUrl = Context.Client.CurrentUser.GetAvatarUrlOrDefault() }, Color = ColorHelper.GetRandomColor(), Description = regexParsed[Random.Next(0, regexParsed.Length)] }; await ReplyAsync("", embed : embed.Build()).ConfigureAwait(false); return(CommandRuntimeResult.FromSuccess()); }