public async Task PlayAsync(string searchQuery) { // Join if not playing. if (_lavaNode.HasPlayer(Context.Guild) is false) { await TryJoinAsync(); } var player = _lavaNode.GetPlayer(Context.Guild); if (Context.User is IVoiceState user && user.VoiceChannel != player.VoiceChannel) { await RespondAsync("You must be in the same voice channel."); return; } await DeferAsync(); // Play from url or search YouTube. var search = Uri.IsWellFormedUriString(searchQuery, UriKind.Absolute) ? await _lavaNode.SearchAsync(SearchType.Direct, searchQuery) : await _lavaNode.SearchYouTubeAsync(searchQuery); if (search.Status is SearchStatus.NoMatches or SearchStatus.LoadFailed) { await RespondAsync($"No matches found for query `{searchQuery.Truncate(100, "...")}`"); return; } // Generate select menu for search results. var selectMenu = new SelectMenuBuilder() .WithPlaceholder("Select a track") .WithCustomId($"tracks:{Context.Interaction.Id}") .WithMinValues(1) .WithMaxValues(1); foreach (var track in search.Tracks.Take(10)) { selectMenu.AddOption( track.Title, track.Url, track.Duration.ToString("c"), new Emoji("▶️")); } var components = new ComponentBuilder().WithSelectMenu(selectMenu); await Context.Interaction.ModifyOriginalResponseAsync(properties => { properties.Content = "Choose a track from the menu to play"; properties.Components = components.Build(); }); }
public async Task Unsubscribe() { //Ensure subscriptions are enabled: if (!_subscriptions.ModuleEnabled) { await RespondAsync("Subscriptions module is currently disabled.", ephemeral : true); return; } //Buy more time to process: await DeferAsync(false); // Get Accounts: var subs = await _subscriptions.GuildSubscriptionsAsync(Context.Guild.Id); // Create Dropdown with channels: var menuBuilder = new SelectMenuBuilder() .WithCustomId("unsubscribe") .WithPlaceholder("Select accounts to remove.") .WithMinValues(0); // Get IG account: InstagramProcessor instagram = new InstagramProcessor(InstagramProcessor.AccountFinder.GetIGAccount()); // Add users to dropdown: foreach (FollowedIGUser user in subs) { foreach (RespondChannel chan in user.SubscribedChannels) { // Get username: string username = await instagram.GetIGUsername(user.InstagramID); if (username == null) { username = "******"; } string channelName = Context.Guild.GetChannel(ulong.Parse(chan.ChannelID))?.Name; // Channel null check: if (channelName is null) { channelName = "Unknown Channel"; } // Add account option to menu: SelectMenuOptionBuilder optBuilder = new SelectMenuOptionBuilder() .WithLabel(username) .WithValue(user.InstagramID + "-" + chan.ChannelID) .WithDescription(username + " in channel " + channelName); menuBuilder.AddOption(optBuilder); } } // Check for subs: if (subs.Length < 1) { await FollowupAsync("No accounts subscribed."); return; } // Make embed: var embed = new EmbedBuilder(); embed.Title = "Unsubscribe"; embed.Description = "Select accounts that you would like to unsubscribe from in the dropdown below."; embed.WithColor(new Color(131, 58, 180)); // Set max count: menuBuilder.WithMaxValues(menuBuilder.Options.Count); // Component Builder: var builder = new ComponentBuilder() .WithSelectMenu(menuBuilder) .WithButton("Delete Message", $"delete-message-{Context.User.Id}", style: ButtonStyle.Danger); // Send message await FollowupAsync(embed : embed.Build(), components : builder.Build()); }
public async Task <CommandResponse> Process(IDiscordBotContext context) { if (context.Interaction is SocketSlashCommand slashCommand) { var settings = SettingsConfig.GetSettings(context.GuildChannel.Guild.Id); if (settings.SelfRoles.Count > 0) { var roles = context.GuildChannel.Guild.Roles.OrderByDescending(r => r.Position).Where(r => settings.SelfRoles.ContainsKey(r.Id)); var roleCount = roles.Count(); if (roleCount > SlashCommandBuilder.MaxOptionsCount) { await slashCommand.RespondAsync($"Too many roles to display in a menu. Complain to management. Max is {SlashCommandBuilder.MaxOptionsCount}.", ephemeral : true); } else if (roleCount > 0) { var menuBuilder = new SelectMenuBuilder() .WithPlaceholder("Select a role") .WithCustomId("role") .WithMinValues(0) .WithMaxValues(roleCount); foreach (var role in roles) { menuBuilder.AddOption(role.Name, role.Id.ToString(), null, string.IsNullOrEmpty(role.Emoji.Name) ? null : role.Emoji); } if (roleCount == 1) { menuBuilder.AddOption("[clear role]", "clear"); } var component = new ComponentBuilder().WithSelectMenu(menuBuilder).Build(); await slashCommand.RespondAsync("choose a role", components : component, ephemeral : true); } } else { await slashCommand.RespondAsync("No roles are self assignable", ephemeral : true); } return(new CommandResponse { IsHandled = true }); } if (context.Message.Channel is SocketGuildChannel guildChannel) { var settings = SettingsConfig.GetSettings(guildChannel.Guild.Id.ToString()); var roles = guildChannel.Guild.Roles.OrderByDescending(r => r.Position).Where(r => settings.SelfRoles.ContainsKey(r.Id)).Select(r => $"``{r.Name.Replace("`", @"\`")}``"); var multiText = new List <string>(); var sb = new StringBuilder(); sb.Append("The following roles are available to self-assign: "); foreach (var role in roles) { if (sb.Length + role.Length + 2 < DiscordConfig.MaxMessageSize) { sb.Append($"{role}, "); } else { multiText.Add(sb.ToString()); sb.Clear(); sb.Append($"{role}, "); } } multiText.Add(sb.ToString()); return(new CommandResponse { MultiText = multiText }); } return(new CommandResponse { Text = "role command does not work in private channels" }); }
private async Task ActivityMessageReceivedAsync(IMessage message) { var command = message.Content.ToLower(); switch (command) { case "!швидка активність": { var builder = new EmbedBuilder() .WithColor(new Color(0xFFFFFF)) .WithDescription("Швидко зберіться у активність на найближчий час"); var menuBuilder = new SelectMenuBuilder() .WithPlaceholder("Оберіть активність") .WithCustomId("QuickActivitySelector") .WithMinValues(1).WithMaxValues(1) .WithOptions(Activity.QuickActivityTypes.Select(x => new SelectMenuOptionBuilder { Label = Translation.ActivityNames[x][0], Value = $"QuickActivity_{x}", Emote = Emote.Parse(CommonData.DiscordEmoji.Emoji.GetActivityEmoji(x)) }).ToList()); var component = new ComponentBuilder() .WithSelectMenu(menuBuilder); await message.Channel.SendMessageAsync(embed : builder.Build(), components : component.Build()); await ServiceCommandsManager.DeleteMessageAsync(message); } break; case "!швидкий рейд": { var builder = new EmbedBuilder() .WithColor(new Color(0xFFFFFF)) .WithDescription("Швидко зберіть рейд на найближчий час"); var menuBuilder = new SelectMenuBuilder() .WithPlaceholder("Оберіть рейд") .WithCustomId("QuickActivitySelector") .WithMinValues(1).WithMaxValues(1) .WithOptions(Activity.ActivityRaidTypes.Select(x => new SelectMenuOptionBuilder { Label = Translation.ActivityRaidTypes[x], Value = $"QuickRaid_{x}", Emote = Emote.Parse(CommonData.DiscordEmoji.Emoji.GetActivityRaidEmoji(x)) }).ToList()); var component = new ComponentBuilder() .WithSelectMenu(menuBuilder); await message.Channel.SendMessageAsync(embed : builder.Build(), components : component.Build()); await ServiceCommandsManager.DeleteMessageAsync(message); } break; case "!допомога": { var helpEmbeds = new BotCommands.SlashCommands.OrganizeActivity().HelpEmbeds; await message.Channel.SendMessageAsync(embeds : helpEmbeds); } break; case "!скасувати": { var msgId = message?.Reference?.MessageId.Value; if (msgId is not null) { await _activityManager.DisableActivityAsync(msgId.Value, message.Author.Id); await ServiceCommandsManager.DeleteMessageAsync(message); } } break; case string c when c.StartsWith("!передати"): { var msgId = message?.Reference?.MessageId.Value; if (msgId is not null && message.MentionedUserIds.Count == 2) { var receiverID = message.MentionedUserIds.Last(); await _activityManager.UserTransferPlaceAsync(msgId.Value, message.Author.Id, receiverID); await ServiceCommandsManager.DeleteMessageAsync(message); } } break; case string c when c.StartsWith("!перенести "): { var msgId = message?.Reference?.MessageId.Value; if (msgId is not null) { try { var date = DateTime.ParseExact(command.Replace("!перенести ", string.Empty), "d.M-H:m", CultureInfo.CurrentCulture); if (date < DateTime.Now) { date = date.AddYears(1); } await _activityManager.RescheduleActivityAsync(msgId.Value, message.Author.Id, date.ToUniversalTime()); await ServiceCommandsManager.DeleteMessageAsync(message); } catch { } } } break; case string c when c.StartsWith("!зарезервувати"): { var msgId = message?.Reference?.MessageId.Value; if (msgId is not null) { await _activityManager.UsersSubscribeAsync(msgId.Value, message.Author.Id, message.MentionedUserIds.Skip(1)); await ServiceCommandsManager.DeleteMessageAsync(message); } } break; case string c when c.StartsWith("!виключити"): { var msgId = message?.Reference?.MessageId.Value; if (msgId is not null) { await _activityManager.UsersUnSubscribeAsync(msgId.Value, message.Author.Id, message.MentionedUserIds.Skip(1)); await ServiceCommandsManager.DeleteMessageAsync(message); } } break; case string c when c.StartsWith("!змінити "): { var msgId = message?.Reference?.MessageId.Value; if (msgId is null) { return; } try { var action = message.Content[9..];
private async Task ActivitySelectMenuExecutedAsync(SocketMessageComponent component) { switch (component.Data.CustomId) { case "QuickActivitySelector": { var builder = new EmbedBuilder() .WithColor(new Color(0xFFFFFF)) .WithDescription("Оберіть зручний час"); var menuBuilder = new SelectMenuBuilder() .WithPlaceholder("Оберіть час") .WithCustomId(string.Join(',', component.Data.Values)) .WithMinValues(1).WithMaxValues(1); var startDate = DateTime.Now; var endDate = startDate.AddHours(12); var tmpDate = startDate.AddMinutes(30); while (tmpDate < endDate) { menuBuilder = menuBuilder.AddOption(tmpDate.ToString("dd.MM HH:mm"), tmpDate.ToString("dd.MM_HH:mm")); tmpDate = tmpDate.AddMinutes(30); } var componentBuilder = new ComponentBuilder() .WithSelectMenu(menuBuilder); await component.RespondAsync(embed : builder.Build(), components : componentBuilder.Build(), ephemeral : true); } break; case string c when c.StartsWith("QuickActivity_"): { var raid = new ActivityContainer() { ChannelID = component.Channel.Id, ActivityType = Enum.Parse <BungieSharper.Entities.Destiny.HistoricalStats.Definitions.DestinyActivityModeType>(c.Split('_')[1]), PlannedDate = DateTime.ParseExact(string.Join(',', component.Data.Values), "dd.MM_HH:mm", CultureInfo.CurrentCulture), ActivityName = null, Description = null, Users = new ulong[] { component.User.Id } }; await component.DeferAsync(); await InitActivityAsync(raid); } break; case string c when c.StartsWith("QuickRaid_"): { var raid = new ActivityContainer() { ChannelID = component.Channel.Id, ActivityType = BungieSharper.Entities.Destiny.HistoricalStats.Definitions.DestinyActivityModeType.Raid, PlannedDate = DateTime.ParseExact(string.Join(',', component.Data.Values), "dd.MM_HH:mm", CultureInfo.CurrentCulture), ActivityName = c.Split('_')[1], Description = null, Users = new ulong[] { component.User.Id } }; await component.DeferAsync(); await InitActivityAsync(raid); } break; default: break; } }