public async Task Add([Remainder] string stuff = null) { var header = await ReplyAsync("**FAQ Entry Setup:** *(reply with cancel to cancel at any time)*"); var msg = await ReplyAsync($"{Context.User.Mention} Please give a name for the new FAQ entry!"); var nameMessage = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); var name = nameMessage.Content; if (name.ToLower() == "cancel") { await header.DeleteAsync(); await msg.DeleteAsync(); return; } await msg.ModifyAsync(properties => properties.Content = $"{Context.User.Mention} Please reply with the whole Message for the FAQ response!"); var contentMessage = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); var content = contentMessage.Content; if (content.ToLower() == "cancel") { await header.DeleteAsync(); await msg.DeleteAsync(); return; } await msg.ModifyAsync(properties => { properties.Content = $"{Context.User.Mention} Is this alright ? *(yes to accept, annything else to cancel)*"; properties.Embed = new EmbedBuilder { Title = $"New FAQ Entry: {name}", Description = content }.Build(); }); var confirmMsg = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); if (confirmMsg.Content.ToLower() == "yes") { await _faqSystem.AddGuildEntryAsync(Context, name.ToLower(), content); await header.DeleteAsync(); await msg.ModifyAsync(p => p.Content = ":ok_hand:"); } else { await header.DeleteAsync(); await msg.DeleteAsync(); } }
public async Task Reset_Points() { _interactiveService = new InteractiveService(_client.GetShardFor(Context.Guild)); var violators = (await _unit.Violators.GetAllAsync(Context.Guild)).ToList(); await ReplyAsync( $"Are you sure you want to reset all points for all Users in {Context.Guild} ? *({violators.Count} total)*" + "\n**Yes** - confirm" + "\n**No** - cancel" + "\n**30 sec timeout**"); var response = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30), new MessageContainsResponsePrecondition("yes")); if (response.Content.ToLower() == "yes") { var changes = ClearPoints(Context.Guild); await ReplyAsync($"{changes} {(changes > 1 ? "entries" : "entry")} deleted!"); var logger = LogManager.GetLogger("Violations"); logger.Info($"Removed all [{changes}] Violator entries for {Context.Guild}"); try { await response.DeleteAsync(); } catch (Exception e) { LogManager.GetLogger("GuildModule").Warn(e, $"Failed to delete message {response.Id} by {response.Author} in {Context.Guild}/{Context.Channel}"); } } else { await ReplyAsync("*Canceled*"); } }
public async Task FavoriteNumber() { await ReplyAsync("What is your favorite number?"); var response = await _interactive.WaitForMessage(Context.User, Context.Channel); await ReplyAsync($"Your favorite number is {response.Content}"); }
public async Task AddToGang([Summary("SLAM EM BOYS")][Remainder] string gangName) { var gang = await _gangRepo.GetGangAsync(gangName, Context.Guild.Id); if (gang.Members.Length == 4) { ReplyError("This gang is already full!"); } var leader = await(Context.Guild as IGuild).GetUserAsync(gang.LeaderId); if (leader != null) { var leaderDM = await leader.CreateDMChannelAsync(); var key = Config.RAND.Next(); await leaderDM.SendAsync($"{Context.User} has requested to join your gang. Please respond with \"{key}\" within 5 minutes to add this user to your gang."); await ReplyAsync($"The leader of {gang.Name} has been informed of your request to join their gang."); var answer = await _interactiveService.WaitForMessage(leaderDM, x => x.Content == key.ToString(), TimeSpan.FromMinutes(5)); if (answer != null) { if (await _gangRepo.InGangAsync(Context.GUser)) { await leaderDM.SendAsync("This user has already joined a different gang."); } else if ((await _gangRepo.GetGangAsync(leader)).Members.Length == 4) { await leaderDM.SendAsync("Your gang is already full."); } else { await _gangRepo.AddMemberAsync(gang, Context.User.Id); await leaderDM.SendAsync($"You have successfully added {Context.User} as a member of your gang."); await Context.User.Id.DMAsync(Context.Client, $"Congrats! {leader} has accepted your request to join {gang.Name}!"); } } } else { await ReplyAsync("The leader of that gang is no longer in this server. ***RIP GANG ROFL***"); } }
public async Task SoftBanAsync(SocketGuildUser target, string argument = "", [Remainder] string reason = null) { if (target.Id == Context.Client.CurrentUser.Id || target.Id == Context.User.Id) { await ReplyAsync(Context.Guild.CurrentUser.GuildPermissions.UseExternalEmojis? "<:ThisIsFine:356157243923628043>" : ":x:"); return; } if (Context.User is SocketGuildUser invoker && invoker.Hierarchy > target.Hierarchy) { if (Context.Guild.CurrentUser.Hierarchy > target.Hierarchy) { if (argument.ToLower() != "-f") { var interactive = new InteractiveService(Context.Client); await ReplyAsync( $"Are you sure you want to Softban **{target}`({target.Id})`**?" + $"\n`-f` to skip this."); var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); var responseResults = new List <string> { "yes", "y" }; if (responseResults.All(res => !response.Content.ToLower().Contains(res))) { await ReplyAsync($"**{target}`({target.Id})`** was not Softbaned!"); return; } } var banRason = argument == "-f" ? reason : $"{argument} {reason}"; await Context.Guild.AddBanAsync(target, 7, !string.IsNullOrWhiteSpace(banRason)?banRason : "No reason specified!"); await Context.Guild.RemoveBanAsync(target); await ReplyAsync($"**{target}`({target.Id})`** was softbaned!"); } else { await ReplyAsync(":warning: Im not permitted to ban this user!"); } }
public async Task Remove([Remainder] string name) { _interactiveService = new InteractiveService(_client.GetShardFor(Context.Guild)); var faq = await _unit.Faqs.GetAsync(Context.Guild, name.ToLower()); if (faq != null) { var msg = await ReplyAsync( $"Please confirm removal of FAQ entry `{faq.Name}` *(yes to accept, annything else to cancel)*"); var responseMsg = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); if (responseMsg.Content.ToLower() == "yes") { _unit.Faqs.Remove(faq); _unit.SaveChanges(); await TryDeleteAsync(responseMsg); await msg.ModifyAsync(p => p.Content = ":ok_hand:"); } else { await msg.DeleteAsync(); } } else { var similar = await _unit.Faqs.GetSimilarAsync(_config, Context.Guild, name); if (similar.Any()) { await ReplyAsync($"No FAQ Entry with the name `{name}` found. Did you mean:\n" + string.Join(" ", similar.Select(pair => "`" + pair.Key.Name + "`"))); } else { await ReplyAsync($"No FAQ entry with the name {name} found."); } } }
public async Task Reset_Points() { var violators = await _mongo.GetCollection <Violator>(Context.Client).GetAllByGuildAsync(Context.Guild.Id); await ReplyAsync( $"Are you sure you want to reset all points for all Users in {Context.Guild} ? *({violators.Count} total)*\n**Yes** - confirm\n**No** - cancel\n**30 sec timeout**"); var response = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30), new MessageContainsResponsePrecondition("yes", "no")); if (response.Content.ToLower() == "yes") { var result = await ClearPoints(Context).ConfigureAwait(false); await ReplyAsync($"{result.DeletedCount} {(result.DeletedCount > 1 ? "entries" : "entry")} deleted!"); var logger = LogManager.GetLogger("Violations"); logger.Info($"Removed all [{result.DeletedCount}] Violator entries for {Context.Guild}"); } else { await ReplyAsync("*Canceled*"); } }
public async Task Marry(SocketCommandContext Context, InteractiveService interactive, SocketGuildUser user) { if (user.Id == Context.User.Id) { await Context.Channel.SendMessageAsync(":no_entry_sign: You can't marry yourself ;_;"); return; } List <MarryData> marryData = new List <MarryData>(); if (_marryDict.ContainsKey(Context.User.Id)) { _marryDict.TryGetValue(Context.User.Id, out marryData); if (marryData != null && marryData.Count > 0) { if (marryData.FirstOrDefault(x => x.UserId == user.Id) != null) { await Context.Channel.SendMessageAsync(":no_entry_sign: You can't marry someone twice!"); return; } if (marryData.Count >= 10) { await Context.Channel.SendMessageAsync(":no_entry_sign: You can't marry more than 10 times!"); return; } } } await Context.Channel.SendMessageAsync($"{user.Mention}, do you want to marry {Context.User.Mention}? :ring:"); var response = await interactive.WaitForMessage(user, Context.Channel, TimeSpan.FromSeconds(20)); if (response == null || !response.Content.Equals("yes", StringComparison.CurrentCultureIgnoreCase)) { await Context.Channel.SendMessageAsync($"{user.Username} has not answered with a Yes :frowning:"); return; } await Context.Channel.SendMessageAsync($"You are now married :couple_with_heart:\n https://media.giphy.com/media/iQ5rGja9wWB9K/giphy.gif"); var newMarriage = new MarryData { UserId = user.Id, MarriedSince = DateTime.UtcNow }; marryData.Add(newMarriage); _marryDict.AddOrUpdate(Context.User.Id, marryData, (key, oldValue) => marryData); marryData = new List <MarryData>(); if (_marryDict.ContainsKey(user.Id)) { _marryDict.TryGetValue(user.Id, out marryData); } newMarriage = new MarryData { UserId = Context.User.Id, MarriedSince = DateTime.UtcNow }; marryData.Add(newMarriage); _marryDict.AddOrUpdate(user.Id, marryData, (key, oldValue) => marryData); _marryDB.SaveMarryData(_marryDict); }
public async Task <string> GetYtURL(SocketCommandContext Context, string name, InteractiveService interactive, Discord.Rest.RestUserMessage msg) { try { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = ytApiKey, ApplicationName = "RankoKanzaki" }); List <string> videos = new List <string>(); int i = 1; var items = new VideoSearch(); List <string> urls = new List <string>(); foreach (var item in items.SearchQuery(name, 1)) { byte[] bytes = System.Text.Encoding.Default.GetBytes(item.Title); string value = System.Text.Encoding.UTF8.GetString(bytes); videos.Add(string.Format("{0})", value)); urls.Add(string.Format("{0})", item.Url)); i++; } int index; if (videos.Count > 1) { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the Index of the YT video you want to add.", }; string vids = ""; int count = 1; foreach (var v in videos) { vids += $"**{count}.** {v}\n"; count++; } eb.Description = vids; var del = await Context.Channel.SendMessageAsync("", false, eb.Build()); var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); await del.DeleteAsync(); if (response == null) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"; }); return("f2"); } if (!Int32.TryParse(response.Content, out index)) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Only add the Index"; }); return("f2"); } if (index > (videos.Count) || index < 1) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Invalid Number"; }); return("f2"); } } else { index = 1; } return(urls[index - 1]); } catch (Exception e) { Console.WriteLine(e); } return("f"); }
private async Task <string> AniInfo([Remainder] string text, Discord.Rest.RestUserMessage msg, AnilistType type) { var client = new GraphQLClient("https://graphql.anilist.co"); List <animeinfo> ch = new List <animeinfo>(); var info = new animeinfo(); string stype = ""; if (type == AnilistType.ANIME) { stype = "ANIME"; } else { stype = "MANGA"; } var request = new GraphQLRequest { Query = @" query($id: Int, $page: Int, $perPage: Int, $search: String) { Page(page: $page, perPage: $perPage) { pageInfo { total currentPage lastPage hasNextPage perPage } media(type: " + stype + @", id: $id, search: $search, isAdult: false) { id title { romaji } siteUrl } } } ", Variables = new { search = text, page = 1, perPage = 20 } }; var response = await client.PostAsync(request); if (response.Data.Page.pageInfo.total.ToObject <int>() > 0) { if (response.Data.Page.pageInfo.total.ToObject <int>() > response.Data.Page.pageInfo.perPage.ToObject <int>()) { for (int i = 0; i < 20; i++) { info.id = response.Data.Page.media[i].id; info.romaji = response.Data.Page.media[i].title.romaji; info.siteURL = response.Data.Page.media[i].siteUrl; ch.Add(info); } } else { for (int i = 0; i < response.Data.Page.pageInfo.total.ToObject <int>(); i++) { info.id = response.Data.Page.media[i].id; info.romaji = response.Data.Page.media[i].title.romaji; info.siteURL = response.Data.Page.media[i].siteUrl; ch.Add(info); } } } else { return("f"); } int index; if (ch.Count > 1 && ch != null) { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the index of character u wanna see.", }; string vids = ""; int count = 1; foreach (var v in ch) { vids += $"**{count}.** {v.romaji}\n"; count++; } eb.Description = vids; var del = await Context.Channel.SendMessageAsync("", false, eb.Build()); var response2 = await _interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); await del.DeleteAsync(); if (response2 == null) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"; }); return("f2"); } if (!Int32.TryParse(response2.Content, out index)) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Only add the Index"; }); return("f2"); } if (index > (ch.Count) || index < 1) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Invalid Number"; }); return("f2"); } } else { index = 1; } return(ch[index - 1].siteURL); }
public async Task BlockAsync() { IUserMessage ourMsg; ourMsg = await ReplyAsync("Would you like to remove a block, or add one? [Remove, Add]"); var mRes = await borkInteract.WaitForMessage(Context.User, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (mRes != null) { if (mRes.Content.ToLower() == "remove") { ourMsg = await DoMessages(ourMsg.Channel, ourMsg, "Please provide the user Id to remove from the block list."); mRes = await borkInteract.WaitForMessage(mRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (mRes != null) { borkConfig.RemoveUserBlock(Convert.ToUInt64(mRes.Content)); } await DoMessages(ourMsg.Channel, ourMsg, $"Thank you, I've removed `{borkClient.GetUser(Convert.ToUInt64(mRes.Content))}` from the Block List."); } else if (mRes.Content.ToLower() == "add") { ourMsg = await DoMessages(ourMsg.Channel, ourMsg, "Please provide the user Id to add."); mRes = await borkInteract.WaitForMessage(mRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (mRes != null) { ulong userId = Convert.ToUInt64(mRes.Content); ourMsg = await DoMessages(ourMsg.Channel, ourMsg, "Is this permanent? [true, false]"); mRes = await borkInteract.WaitForMessage(mRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (mRes != null) { bool Permanent = Convert.ToBoolean(mRes.Content); ourMsg = await DoMessages(ourMsg.Channel, ourMsg, "Please provide a reason for the block."); mRes = await borkInteract.WaitForMessage(mRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (mRes != null) { borkConfig.AddUserBlock(userId, Permanent, DateTime.Now, mRes.Content); await DoMessages(ourMsg.Channel, ourMsg, $"Thank you, I've added `{borkClient.GetUser(userId)}` to the block list.\n\n`Reason:` {mRes.Content}\n`Permanent:` {Permanent}"); } } } } else { await DoMessages(ourMsg.Channel, ourMsg, "Your request was invalid, try again."); } } else { await DoMessages(ourMsg.Channel, ourMsg, "Your request timed out, try again."); } //if (borkConfig.BlockedUsers.ContainsKey(Id)) // await ReplyAsync("That user has already been blocked :x:"); //else //{ // borkConfig.AddUserBlock(Id, isTemp, DateTime.Today, reason); // await ReplyAsync($"Alrighty, I've added `{borkClient.GetUser(Id).Username}` to the block list.\n\n`Reason:` *{reason}*\n`Temp:` *{isTemp}*"); //} }
public async Task <string> GetYtURL(SocketCommandContext Context, string name, InteractiveService interactive, Discord.Rest.RestUserMessage msg) { try { var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = ytApiKey, ApplicationName = "SoraBot" //this.GetType().ToString() }); var searchListRequest = youtubeService.Search.List("snippet"); var search = System.Net.WebUtility.UrlEncode(name); searchListRequest.Q = search; searchListRequest.MaxResults = 10; var searchListResponse = await searchListRequest.ExecuteAsync(); List <string> videos = new List <string>(); List <Google.Apis.YouTube.v3.Data.SearchResult> videosR = new List <Google.Apis.YouTube.v3.Data.SearchResult>(); foreach (var searchResult in searchListResponse.Items) { switch (searchResult.Id.Kind) { case "youtube#video": videos.Add(String.Format("{0}", searchResult.Snippet.Title)); videosR.Add(searchResult); break; } } int index; if (videos.Count > 1) { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the Index of the YT video you want to add.", }; string vids = ""; int count = 1; foreach (var v in videos) { vids += $"**{count}.** {v}\n"; count++; } eb.Description = vids; var del = await Context.Channel.SendMessageAsync("", embed : eb); var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); await del.DeleteAsync(); if (response == null) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"; }); return("f2"); } if (!Int32.TryParse(response.Content, out index)) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Only add the Index"; }); return("f2"); } if (index > (videos.Count) || index < 1) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Invalid Number"; }); return("f2"); } } else { index = 1; } return($"https://www.youtube.com/watch?v={videosR[index-1].Id.VideoId}"); //await Context.Channel.SendMessageAsync(String.Format("Videos: \n{0}\n", String.Join("\n", videos))); } catch (Exception e) { Console.WriteLine(e); await SentryService.SendError(e, Context); } return("f"); }
public async Task GetManga(SocketCommandContext Context, string manga, InteractiveService interactive) { try { if (Environment.TickCount > timeToUpdate) { await RequestAuth(); } var search = System.Net.WebUtility.UrlEncode(manga); var link = "http://anilist.co/api/manga/search/" + Uri.EscapeUriString(search); using (var http = new HttpClient()) { var res = await http.GetStringAsync(link + $"?access_token={anilistToken}").ConfigureAwait(false); var results = JArray.Parse(res); int index; if (results.Count > 1) { string choose = ""; var ebC = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the Index of the Manga you want more info about.", }; int count = 1; foreach (var r in results) { choose += $"**{count}.** {r["title_english"]}\n"; count++; } ebC.Description = choose; await Context.Channel.SendMessageAsync("", embed : ebC); var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); if (response == null) { await Context.Channel.SendMessageAsync($":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"); return; } if (!Int32.TryParse(response.Content, out index)) { await Context.Channel.SendMessageAsync(":no_entry_sign: Only add the Index"); return; } if (index > (results.Count) || index < 1) { await Context.Channel.SendMessageAsync(":no_entry_sign: Invalid Number"); return; } } else { index = 1; } var smallObj = JArray.Parse(res)[index - 1]; var manData = await http.GetStringAsync("http://anilist.co/api/manga/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false); //await Context.Channel.SendMessageAsync(manData); //return await Task.Run(() => { try { return JsonConvert.DeserializeObject<AnimeResult>(aniData); } catch { return null; } }).ConfigureAwait(false); var mangaDa = JsonConvert.DeserializeObject <MangaResult>(manData); var eb = mangaDa.GetEmbed(); eb.WithFooter(x => { x.Text = $"Requested by {Context.User.Username}#{Context.User.Discriminator}"; x.IconUrl = (Context.User.GetAvatarUrl()); }); eb.Build(); await Context.Channel.SendMessageAsync("", false, eb); } } catch (Exception) { await Context.Channel.SendMessageAsync(":no_entry_sign: Couldn't find Manga. Try later or try another one."); } }
public async Task GetImdb(SocketCommandContext Context, string target, InteractiveService interactive) { try { await Context.Channel.TriggerTypingAsync(); var movieSimple = await TheMovieDbProvider.FindMovie(target); if (movieSimple == null || movieSimple.Length < 1) { await Context.Channel.SendMessageAsync(":no_entry_sign: Couldn't find movie/series"); return; } int index; if (movieSimple.Length > 1) { string choose = ""; var ebC = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the Index of the Movie you want more info about." }; int count = 1; foreach (var movie in movieSimple) { choose += $"**{count}.** {movie.title} ({(movie.release_date.Length > 4 ? movie.release_date.Remove(4) : (string.IsNullOrWhiteSpace(movie.release_date)? "NoDate": movie.release_date))})\n"; count++; } ebC.Description = choose; var msg = await Context.Channel.SendMessageAsync("", embed : ebC); var response = await interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); if (response == null) { await Context.Channel.SendMessageAsync($":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"); return; } if (!Int32.TryParse(response.Content, out index)) { await Context.Channel.SendMessageAsync(":no_entry_sign: Only add the Index"); return; } if (index > (movieSimple.Length) || index < 1) { await Context.Channel.SendMessageAsync(":no_entry_sign: Invalid Number"); return; } } else { index = 1; } //var smallObj = JToken.Parse(movieSimple[index - 1]); var finalMovie = TheMovieDbProvider.FindFinalMovie(movieSimple[index - 1].id.ToString()).Result; var eb = finalMovie.GetEmbed(); eb.WithFooter(x => { x.Text = $"Requested by {Context.User.Username}#{Context.User.Discriminator}"; x.IconUrl = (Context.User.GetAvatarUrl()); }); eb.Build(); await Context.Channel.SendMessageAsync("", false, eb); } catch (Exception e) { await Context.Channel.SendMessageAsync(":no_entry_sign: Couldn't find IMDb entry. Try later or try another one."); await SentryService.SendError(e, Context); } }
private async Task <string> ChInfo([Remainder] string text, Discord.Rest.RestUserMessage msg) { List <ch_info> ch = new List <ch_info>(); var info = new ch_info(); var client = new WebClient(); string pageSourceCode = client.DownloadString(string.Format("https://gbf.wiki/index.php?title=Special:Search&profile=default&fulltext=Search&search={0}", text)); System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(pageSourceCode, "<div class=(.*?)><a href=\"(.*?)\" title=\"(.*?)\" data-serp-pos=\"(.*?)\">"); if (mc.Count > 0) { foreach (System.Text.RegularExpressions.Match match in mc) { info.name = match.Groups[3].Value; info.page = match.Groups[2].Value; ch.Add(info); } } else { return("f"); } int index; if (ch.Count > 1 && ch != null) { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the index of character u wanna see.", }; string vids = ""; int count = 1; foreach (var v in ch) { vids += $"**{count}.** {v.name}\n"; count++; } eb.Description = vids; var del = await Context.Channel.SendMessageAsync("", false, eb.Build()); var response = await _interactive.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); await del.DeleteAsync(); if (response == null) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"; }); return("f2"); } if (!Int32.TryParse(response.Content, out index)) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Only add the Index"; }); return("f2"); } if (index > (ch.Count) || index < 1) { await msg.ModifyAsync(x => { x.Content = $":no_entry_sign: Invalid Number"; }); return("f2"); } } else { index = 1; } return($"https://gbf.wiki" + ch[index - 1].page); }
/* * public void Stop() //Example to make the timer stop running * { * _timer.Change(Timeout.Infinite, Timeout.Infinite); * } * * public void Restart() //Example to restart the timer * { * _timer.Change(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(30)); * }*/ public async Task DelteReminder(SocketCommandContext Context) { try { if (!_remindDict.ContainsKey(Context.User.Id)) { await Context.Channel.SendMessageAsync(":no_entry_sign: You have no Reminders!"); return; } List <RemindData> data = new List <RemindData>(); _remindDict.TryGetValue(Context.User.Id, out data); if (data.Count < 1) { await Context.Channel.SendMessageAsync(":no_entry_sign: You have no Reminders!"); return; } var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Title = "Enter the Index of the Reminder you want to remove.", }; string reminders = ""; int count = 1; foreach (var v in data) { reminders += $"**{count}.** {v.message}\n"; count++; } reminders += $"**{count}.** Cancel"; eb.Description = reminders; var del = await Context.Channel.SendMessageAsync("", embed : eb); var response = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(20)); await del.DeleteAsync(); if (response == null) { await Context.Channel.SendMessageAsync($":no_entry_sign: Answer timed out {Context.User.Mention} (≧д≦ヾ)"); return; } int index = 0; if (!Int32.TryParse(response.Content, out index)) { await Context.Channel.SendMessageAsync($":no_entry_sign: Only add the Index"); return; } if (index > (data.Count + 1) || index < 1) { await Context.Channel.SendMessageAsync($":no_entry_sign: Invalid Number"); return; } if (index == count) { await Context.Channel.SendMessageAsync($":no_entry_sign: Action Cancelled"); return; } index -= 1; var msgThatGetsRemoved = data[index].message; data.RemoveAt(index); _remindDict.TryUpdate(Context.User.Id, data); ReminderDB.SaveReminders(_remindDict); await Context.Channel.SendMessageAsync($":white_check_mark: Successfully removed Reminder: `{msgThatGetsRemoved}`"); } catch (Exception e) { Console.WriteLine(e); await SentryService.SendError(e, Context); } }
public async Task AddSongQueue([Remainder] string query) { QueueInfo curQueue = new QueueInfo(); if (guildQueue.ContainsKey(Context.Guild.Id)) { guildQueue.TryGetValue(Context.Guild.Id, out curQueue); } if (query.ToLower().Contains("youtube.com")) { Video grab = await borkTube.GetVideoAsync(YoutubeClient.ParseVideoId(query)); curQueue.Songs.Add(new Song() { SongTitle = grab.Title, SongId = grab.Id, SongURL = grab.GetUrl(), SongDuration = grab.Duration, DiscordRequester = Context.Message.Author }); guildQueue.Remove(Context.Guild.Id); guildQueue.Add(Context.Guild.Id, curQueue); await ReplyAsync($"Awesome, I added `{grab.Title}` to your queue"); } else { IEnumerable <VideoInformation> searchResults = new VideoSearch().SearchQuery(query, 1).Take(10); var borkMsg = await Context.Channel.SendMessageAsync($"***- Please respond with the song number you want -***\n\n{OrganizeList(searchResults)}"); var uRes = await borkInteract.WaitForMessage(Context.Message.Author, borkMsg.Channel, TimeSpan.FromSeconds(60)); if (int.TryParse(uRes.Content, out int result)) { if (result >= 10) { await DoMessages(borkMsg.Channel, borkMsg, "**The song number you gave was not listed, please try again.**"); } else { Video chosen = await borkTube.GetVideoAsync(YoutubeClient.ParseVideoId(searchResults.ElementAt(result).Url)); curQueue.Songs.Add(new Song() { SongTitle = chosen.Title, SongId = chosen.Id, SongURL = chosen.GetUrl(), SongDuration = chosen.Duration, DiscordRequester = uRes.Author }); guildQueue.Remove(Context.Guild.Id); guildQueue.Add(Context.Guild.Id, curQueue); await DoMessages(borkMsg.Channel, borkMsg, $"Awesome, I added `{chosen.Title}` to your queue"); } } else { await DoMessages(borkMsg.Channel, borkMsg, "**The response you gave was not valid, please try again.**"); } } }
public async Task Add([Remainder] string name = null) { _interactiveService = new InteractiveService(_client.GetShardFor(Context.Guild)); var toDelete = new List <IMessage>(); var header = await ReplyAsync("**FAQ Entry Setup:** *(reply with cancel to cancel at any time)*"); IUserMessage msg = await ReplyAsync("."); IUserMessage nameMessage = null; if (name == null) { await msg.ModifyAsync(properties => properties.Content = $"{Context.User.Mention} Please give a name for the new FAQ entry!"); nameMessage = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); name = nameMessage.Content; if (name.ToLower() == "cancel") { toDelete.Add(Context.Message); toDelete.Add(header); toDelete.Add(msg); toDelete.Add(nameMessage); await TryDeleteBatchAsync(Context.Channel, Context.User as IGuildUser, toDelete); return; } } await msg.ModifyAsync(properties => properties.Content = $"{Context.User.Mention} Please reply with the whole Message for the FAQ response!"); var contentMessage = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(90)); var content = contentMessage.Content; if (content.ToLower() == "cancel") { toDelete.Add(Context.Message); toDelete.Add(header); toDelete.Add(msg); if (nameMessage != null) { toDelete.Add(nameMessage); } toDelete.Add(contentMessage); await TryDeleteBatchAsync(Context.Channel, Context.User as IGuildUser, toDelete); return; } await msg.ModifyAsync(properties => { properties.Content = $"{Context.User.Mention} Is this alright ? *(yes to accept, annything else to cancel)*"; properties.Embed = new EmbedBuilder { Title = $"New FAQ Entry: {name}", Description = content }.Build(); }); var confirmMsg = await _interactiveService.WaitForMessage(Context.User, Context.Channel, TimeSpan.FromSeconds(30)); if (confirmMsg.Content.ToLower() == "yes") { toDelete.Add(header); if (nameMessage != null) { toDelete.Add(nameMessage); } toDelete.Add(contentMessage); toDelete.Add(confirmMsg); await TryDeleteBatchAsync(Context.Channel, Context.User as IGuildUser, toDelete); var faq = await _unit.Faqs.GetAsync(Context.Guild, name.ToLower()); if (faq == null) { await _unit.Faqs.AddAsync(new Faq { GuildId = Context.Guild.Id, Name = name.ToLower(), Content = content, CreatorId = Context.User.Id, CreatedAt = DateTime.UtcNow, LastUsed = DateTime.MinValue, UseCount = 0 }); _unit.SaveChanges(); await msg.ModifyAsync(p => p.Content = ":ok_hand:"); } else { await msg.ModifyAsync(p => p.Content = $":exclamation: Faq entry with the name `{name}` already existing"); } } else { toDelete.Add(Context.Message); toDelete.Add(header); toDelete.Add(msg); if (nameMessage != null) { toDelete.Add(nameMessage); } toDelete.Add(contentMessage); toDelete.Add(confirmMsg); await TryDeleteBatchAsync(Context.Channel, Context.User as IGuildUser, toDelete); } }
public async Task HelpAsync() { string info = null; IUserMessage ourMsg = null; try { ourMsg = await Context.User.SendMessageAsync("Hello! What can I assist you with today? [Module, Command]"); } catch (HttpException ex) when(ex.DiscordCode == 50007) { ourMsg = await ReplyAsync("Hello! What can I assist you with today? [Module, Command]"); } finally { var uRes = await borkInteract.WaitForMessage(Context.User, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (uRes != null) { if (uRes.Content.ToLower() == "module") { foreach (var m in borkCommands.Modules.OrderBy(x => x.Name)) { info += $"• **{m.Name}:** *{m.Summary ?? "No summary provided"}*\n"; } ourMsg = await DoMessages(uRes.Channel, ourMsg, $"What module would you like to see commands for?\n\n__List of Modules__\n{info}"); uRes = await borkInteract.WaitForMessage(uRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (uRes != null) { var src = borkCommands.Modules.FirstOrDefault(x => x.Name.ToLower() == uRes.Content.ToLower()); if (src == null) { await DoMessages(ourMsg.Channel, ourMsg, "**The module name you gave was not valid, please use the help command again.**"); } else { info = null; foreach (var c in src.Commands) { info += $"• **{c.Name}**\n*Summary: {c.Summary ?? "No summar provided"}*\n\n"; } await DoMessages(ourMsg.Channel, ourMsg, $"Here you go, glad I could help!\n\n__Module Commands__\n{info}"); } } else { await DoMessages(ourMsg.Channel, ourMsg, "**Your request timed out, please use the help command again.**"); } } else if (uRes.Content.ToLower() == "command") { ourMsg = await DoMessages(ourMsg.Channel, ourMsg, "What command would you like to see information about?"); uRes = await borkInteract.WaitForMessage(uRes.Author, ourMsg.Channel, TimeSpan.FromSeconds(60)); if (uRes != null) { var src = borkCommands.Search(Context, uRes.Content); if (!src.IsSuccess) { await DoMessages(ourMsg.Channel, ourMsg, "**The command name you gave was not valid, please use the help command again.**"); } else { info = null; foreach (var c in src.Commands) { info += $"• **{c.Command.Name} - [Aliases: {string.Join(", ", c.Command.Aliases) ?? "No Aliases"}]**\n*Summary: {c.Command.Summary ?? "No summar provided"}*\n*Usage: {borkConfig.LoadedSecrets.BotPrefix + c.Command.Remarks}*"; } await DoMessages(ourMsg.Channel, ourMsg, $"Here you go, glad I could help!\n\n__Command Information__\n{info}"); } } else { await DoMessages(ourMsg.Channel, ourMsg, "**Your request timed out, please use the help command again.**"); } } else { await DoMessages(ourMsg.Channel, ourMsg, "**The option you gave was not valid, please use the help command again.**"); } } else { await DoMessages(ourMsg.Channel, ourMsg, "**Your request timed out, please use the help command again.**"); } } }