public async Task RemoveTextChannel(CommandContext ctx, [Description("Channel to delete")][RemainingText] DiscordChannel channel = null) { // Set the current channel for deletion if one isn't provided by the user channel = channel ?? ctx.Channel; var prompt = await ctx.RespondAsync("You're about to delete the " + Formatter.Bold(channel.ToString()) + "\nRespond with **yes** if you want to proceed or wait 10 seconds to cancel the operation.").ConfigureAwait(false); var interactivity = await BotServices.GetUserInteractivity(ctx, "yes", 10).ConfigureAwait(false); if (interactivity.Result is null) { await ctx.RespondAsync(Resources.REQUEST_TIMEOUT).ConfigureAwait(false); } else { await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); await BotServices.RemoveMessage(prompt).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully deleted " + Formatter.Bold(channel.Name), EmbedType.Good).ConfigureAwait(false); await channel.DeleteAsync().ConfigureAwait(false); } }
public async Task Twitch(CommandContext ctx, [Description("Channel to find on Twitch")][RemainingText] string query) { if (!BotServices.CheckUserInput(query)) { return; } var results = await TwitchService.GetTwitchDataAsync(query).ConfigureAwait(false); if (results.Stream.Count == 0) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_TWITCH, EmbedType.Missing).ConfigureAwait(false); } else { var stream = results.Stream[0]; var output = new DiscordEmbedBuilder() .WithTitle(stream.UserName + " is live on Twitch!") .WithDescription(stream.Title) .AddField("Start Time:", stream.StartTime, true) .AddField("View Count:", stream.ViewCount.ToString(), true) .WithImageUrl(stream.ThumbnailUrl.Replace("{width}", "500").Replace("{height}", "300")) .WithUrl("https://www.twitch.tv/" + stream.UserName) .WithColor(new DiscordColor("#6441A5")); await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); } }
public async Task ImgSearch(CommandContext ctx, string searchTag) { var emojis = new PaginationEmojis() //emojis to be used in the pagination { Left = DiscordEmoji.FromName(ctx.Client, ":arrow_backward:"), Right = DiscordEmoji.FromName(ctx.Client, ":arrow_forward:"), SkipLeft = null, SkipRight = null }; IamagesAPIWrapper api = new IamagesAPIWrapper(); var response = api.postSearch(searchTag); if (response.FileIDs.Length != 0) // no search was found { List <Page> pages = new List <Page>(); // paginated embeds to be sent var interactivity = ctx.Client.GetInteractivity(); int count = 0; foreach (int fileID in response.FileIDs) { count++; var imgInfo = api.getImgInfo(fileID); var embed = defaultImgEmbed(imgInfo, api); embed.WithTitle($"Image #{count}/{response.FileIDs.Length}"); var page = new Page($"Images Found! Searching for: `{response.searchTag}`\nPress :stop_button: to stop interacting", embed); pages.Add(page); } await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User, pages, emojis); } else { await BotServices.SendEmbedAsync(ctx, "Sorry! No Iamages were found!", "Similar descriptions were either not found or something else went wrong!", ResponseType.Warning); } }
public async Task Weather(CommandContext ctx, [Description("Location to retrieve weather data from")][RemainingText] string query) { if (!BotServices.CheckUserInput(query)) { return; } var results = await GoogleService.GetWeatherDataAsync(query).ConfigureAwait(false); if (results.COD == 404) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_LOCATION, EmbedType.Missing).ConfigureAwait(false); } else { Func <double, double> format = GoogleService.CelsiusToFahrenheit; var output = new DiscordEmbedBuilder() .WithTitle(":partly_sunny: Current weather in " + results.Name + ", " + results.Sys.Country) .AddField("Temperature", $"{results.Main.Temperature:F1}°C / {format(results.Main.Temperature):F1}°F", true) .AddField("Humidity", $"{results.Main.Humidity}%", true) .AddField("Wind Speed", $"{results.Wind.Speed}m/s", true) .WithUrl("https://openweathermap.org/city/" + results.ID) .WithColor(SharedData.DefaultColor); await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); } }
public async Task Warn(CommandContext ctx, [Description("Server user to warn")] DiscordMember member, [Description("Warning message")][RemainingText] string reason = null) { var output = new DiscordEmbedBuilder() .WithTitle("Warning received!") .WithDescription(Formatter.Bold(ctx.Guild.Name) + " has issued you a server warning!") .AddField("Sender:", ctx.Member.Username + "#" + ctx.Member.Discriminator, true) .AddField("Server Owner:", ctx.Guild.Owner.Username + "#" + ctx.Guild.Owner.Discriminator, true) .WithThumbnailUrl(ctx.Guild.IconUrl) .WithTimestamp(DateTime.Now) .WithColor(DiscordColor.Red); if (!string.IsNullOrWhiteSpace(reason)) { output.AddField("Warning message:", reason); } var dm = await member.CreateDmChannelAsync().ConfigureAwait(false); if (dm is null) { await BotServices.SendEmbedAsync(ctx, "Unable to direct message this user", EmbedType.Warning).ConfigureAwait(false); } else { await dm.SendMessageAsync(embed : output.Build()).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully sent a warning to " + Formatter.Bold(member.Username), EmbedType.Good).ConfigureAwait(false); } }
public async Task Poll(CommandContext ctx, [Description("Question to be polled")][RemainingText] string question) { if (!BotServices.CheckUserInput(question)) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_POLL_QUESTION, EmbedType.Warning).ConfigureAwait(false); } else { var interactivity = ctx.Client.GetInteractivity(); var pollOptions = new List <DiscordEmoji>(); pollOptions.Add(DiscordEmoji.FromName(ctx.Client, ":thumbsup:")); pollOptions.Add(DiscordEmoji.FromName(ctx.Client, ":thumbsdown:")); var duration = new TimeSpan(0, 0, 3, 0, 0); var output = new DiscordEmbedBuilder().WithDescription(ctx.User.Mention + "asked: " + question + "\nThis poll ends in 3 minutes."); var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); foreach (var react in pollOptions) { await message.CreateReactionAsync(react).ConfigureAwait(false); } var pollResult = await interactivity.CollectReactionsAsync(message, duration).ConfigureAwait(false); var results = pollResult.Where(x => pollOptions.Contains(x.Emoji)).Select(x => $"{x.Emoji} wins the poll with **{x.Total}** votes"); await ctx.RespondAsync(string.Join("\n", results)).ConfigureAwait(false); } }
public async Task PruneUsers(CommandContext ctx, [Description("Number of days the user had to be inactive to get pruned")][RemainingText] int days = 7) { if (days < 1 || days > 30) { await BotServices.SendEmbedAsync(ctx, "Number of days must be between 1 and 30", EmbedType.Warning).ConfigureAwait(false); } int count = await ctx.Guild.GetPruneCountAsync(days).ConfigureAwait(false); if (count == 0) { await ctx.RespondAsync("No inactive members found to prune").ConfigureAwait(false); return; } var prompt = await ctx.RespondAsync($"Pruning will remove {Formatter.Bold(count.ToString())} member(s).\nRespond with **yes** to continue.").ConfigureAwait(false); var interactivity = await BotServices.GetUserInteractivity(ctx, "yes", 10).ConfigureAwait(false); if (interactivity.Result is null) { return; } await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); await BotServices.RemoveMessage(prompt).ConfigureAwait(false); await ctx.Guild.PruneAsync(days).ConfigureAwait(false); }
public async Task Clean(CommandContext ctx, [Description("Number of message to remove from the current channel")] int limit = 2) { var messages = await ctx.Channel.GetMessagesAsync(BotServices.LimitToRange(limit)).ConfigureAwait(false); await ctx.Channel.DeleteMessagesAsync(messages).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, Formatter.Bold(messages.Count.ToString()) + " message(s) removed from #" + ctx.Channel.Name, EmbedType.Good).ConfigureAwait(false); }
public async Task SetUserRole(CommandContext ctx, [Description("Server user to get role assigned")] DiscordMember member, [Description("Server role to assign to the user")][RemainingText] DiscordRole role) { member = member ?? ctx.Member; await member.GrantRoleAsync(role).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, member.DisplayName + " been granted the role " + Formatter.Bold(role.Name), EmbedType.Good).ConfigureAwait(false); }
public async Task Purge(CommandContext ctx, [Description("Server user whose messages will be purged")] DiscordMember member, [Description("Number of messages to purge")][RemainingText] int limit = 0) { var messages = await ctx.Channel.GetMessagesAsync(BotServices.LimitToRange(limit)).ConfigureAwait(false); await ctx.Channel.DeleteMessagesAsync(messages.Where(m => m.Author.Id == member.Id)).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, $"Purged **{limit}** messages by {member.Username}#{member.Discriminator} (ID:{member.Id})", EmbedType.Good).ConfigureAwait(false); }
public async Task SetUserName(CommandContext ctx, [Description("Server user to nickname")] DiscordMember member, [Description("The new nickname")][RemainingText] string name = null) { member = member ?? ctx.Member; var nickname = member.DisplayName; await member.ModifyAsync(usr => usr.Nickname = name).ConfigureAwait(false); var response = (!string.IsNullOrWhiteSpace(name)) ? $"{nickname}'s nickname has been changed to **{name}**" : $"{nickname}'s nickname has been reset."; await BotServices.SendEmbedAsync(ctx, response, EmbedType.Good).ConfigureAwait(false); }
public async Task RemoveUserRole(CommandContext ctx, [Description("Server user to get revoked")] DiscordMember member, [Description("Server role to revoke from user")][RemainingText] DiscordRole role) { if (role != null) { member = member ?? ctx.Member; await member.RevokeRoleAsync(role).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, Formatter.Bold(member.DisplayName) + " has been removed from the role " + Formatter.Bold(role.Name), EmbedType.Good).ConfigureAwait(false); } }
public async Task SetBotAvatar(CommandContext ctx, [Description("Image URL. Must be in jpg, png or img format.")] string query) { var stream = BotServices.CheckImageInput(ctx, query).Result; if (stream.Length <= 0) { return; } await ctx.Client.UpdateCurrentUserAsync(avatar : stream).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, SharedData.Name + " avatar has been updated!", EmbedType.Good).ConfigureAwait(false); }
public async Task DeleteRole(CommandContext ctx, [Description("Server role to delete")][RemainingText] DiscordRole role = null) { if (role is null) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_ROLE_EXISTING, EmbedType.Warning).ConfigureAwait(false); } else { await role.DeleteAsync().ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully removed the server role " + Formatter.Bold(role.Name), EmbedType.Good).ConfigureAwait(false); } }
public async Task SteamUser(CommandContext ctx, [Description("User to find on Steam")][RemainingText] string query) { if (!BotServices.CheckUserInput(query)) { return; } var profile = SteamService.GetSteamProfileAsync(query).Result; var summary = SteamService.GetSteamSummaryAsync(query).Result; if (profile is null && summary is null) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false); }
public async Task SetServerName(CommandContext ctx, [Description("New server name")][RemainingText] string name = "") { if (string.IsNullOrWhiteSpace(name) || (name.Length > 100)) { await BotServices.SendEmbedAsync(ctx, "Server name cannot be blank or over 100 characters!", EmbedType.Warning).ConfigureAwait(false); } else { await ctx.Guild.ModifyAsync(srv => srv.Name = name).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Server name has been changed to " + Formatter.Bold(name), EmbedType.Good).ConfigureAwait(false); } }
public async Task CreateRole(CommandContext ctx, [Description("New role name")][RemainingText] string role = "") { if (string.IsNullOrWhiteSpace(role)) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_ROLE_NAME, EmbedType.Warning).ConfigureAwait(false); } else { await ctx.Guild.CreateRoleAsync(role).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully created the server role " + Formatter.Bold(role), EmbedType.Good).ConfigureAwait(false); } }
public async Task CreateChannelCategory(CommandContext ctx, [Description("New category name")][RemainingText] string name) { if (!BotServices.CheckChannelName(name)) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_CHANNEL_NAME, EmbedType.Warning).ConfigureAwait(false); } else { var category = await ctx.Guild.CreateChannelCategoryAsync(name.Trim()).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, "Successfully created category " + Formatter.Bold(category.Name), EmbedType.Good).ConfigureAwait(false); } }
public async Task GetAmiibo(CommandContext ctx, [Description("Name of the Amiibo figurine")][RemainingText] string query) { if (!BotServices.CheckUserInput(query)) { return; } var results = await AmiiboService.GetAmiiboDataAsync(query).ConfigureAwait(false); if (results is null) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false); } else { foreach (var amiibo in results.Amiibo) { var output = new DiscordEmbedBuilder() .WithTitle(amiibo.Name) .AddField("Amiibo Series", amiibo.AmiiboSeries, true) .AddField("Game Series", amiibo.GameSeries, true) .AddField(":flag_us: Release:", amiibo.ReleaseDate.American, true) .AddField(":flag_jp: Release:", amiibo.ReleaseDate.Japanese, true) .AddField(":flag_eu: Release:", amiibo.ReleaseDate.European, true) .AddField(":flag_au: Release:", amiibo.ReleaseDate.Australian, true) .WithImageUrl(amiibo.Image) .WithFooter(!amiibo.Equals(results.Amiibo.Last()) ? "Type 'next' within 10 seconds for the next amiibo" : "This is the last found amiibo on the list.") .WithColor(new DiscordColor("#E70009")); var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); if (results.Amiibo.Count == 1) { continue; } var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); if (interactivity.Result is null) { break; } await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); if (!amiibo.Equals(results.Amiibo.Last())) { await BotServices.RemoveMessage(message).ConfigureAwait(false); } } } }
public async Task SetServerAvatar(CommandContext ctx, [Description("Image URL. Must be in jpg, png or img format.")] string query) { try { var stream = BotServices.CheckImageInput(ctx, query).Result; await ctx.Guild.ModifyAsync(chn => chn.Icon = stream).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, ctx.Guild.Name + " server avatar has been updated!", EmbedType.Good).ConfigureAwait(false); } catch { await BotServices.SendEmbedAsync(ctx, ctx.Guild.Name + " server avatar has not been updated!", EmbedType.Error).ConfigureAwait(false); } }
public async Task UrbanDictionary(CommandContext ctx, [Description("Query to pass to Urban Dictionary")][RemainingText] string query) { if (!BotServices.CheckUserInput(query)) { return; } var results = await DictionaryService.GetDictionaryDefinitionAsync(query).ConfigureAwait(false); if (results.ResultType == "no_results" || results.List.Count == 0) { await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false); } else { foreach (var definition in results.List) { var output = new DiscordEmbedBuilder() .WithTitle("Urban Dictionary definition for " + Formatter.Bold(query)) .WithDescription(!string.IsNullOrWhiteSpace(definition.Author) ? "Submitted by: " + definition.Author : string.Empty) .AddField("Definition", definition.Definition.Length < 500 ? definition.Definition : definition.Definition.Take(500) + "...") .AddField("Example", definition.Example ?? "None") .AddField(":thumbsup:", definition.ThumbsUp.ToString(), true) .AddField(":thumbsdown:", definition.ThumbsDown.ToString(), true) .WithUrl(definition.Permalink) .WithFooter(!definition.Equals(results.List.Last()) ? "Type 'next' within 10 seconds for the next definition" : "This is the last found definition on the list.") .WithColor(new DiscordColor("#1F2439")); var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false); if (results.List.Count == 1) { continue; } var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false); if (interactivity.Result is null) { break; } await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false); if (!definition.Equals(results.List.Last())) { await BotServices.RemoveMessage(message).ConfigureAwait(false); } } } }
public async Task SetChannelName(CommandContext ctx, [Description("Channel to rename")] DiscordChannel channel, [Description("New channel name")][RemainingText] string name) { if (!BotServices.CheckChannelName(name)) { await BotServices.SendEmbedAsync(ctx, Resources.ERR_CHANNEL_NAME, EmbedType.Warning).ConfigureAwait(false); } else { var old_name = channel.Name; await channel.ModifyAsync(new Action <ChannelEditModel>(m => m.Name = name.Trim().Replace(" ", "-"))).ConfigureAwait(false); await BotServices.SendEmbedAsync(ctx, $"Successfully renamed the channel " + Formatter.Bold(old_name) + " to " + Formatter.Bold(name), EmbedType.Good).ConfigureAwait(false); } }