public async Task SearchYouTube([Remainder] string args = "") { string searchFor = string.Empty; var embed = new EmbedBuilder(); var embedThumb = Context.User.GetAvatarUrl(); StringBuilder sb = new StringBuilder(); List <Google.Apis.YouTube.v3.Data.SearchResult> results = null; embed.ThumbnailUrl = embedThumb; if (string.IsNullOrEmpty(args)) { embed.Title = $"No search term provided!"; embed.WithColor(new Color(255, 0, 0)); sb.AppendLine("Please provide a term to search for!"); embed.Description = sb.ToString(); await _channelServices.Reply(Context, embed); return; } else { searchFor = args; embed.WithColor(new Color(0, 255, 0)); results = await _youtubeApi.SearchChannelsAsync(searchFor); } if (results != null) { string videoUrlPrefix = $"https://www.youtube.com/watch?v="; embed.Title = $"YouTube Search For (**{searchFor}**)"; var thumbFromVideo = results.Where(r => r.Id.Kind == "youtube#video").Take(1).FirstOrDefault(); if (thumbFromVideo != null) { embed.ThumbnailUrl = thumbFromVideo.Snippet.Thumbnails.Default__.Url; } foreach (var result in results.Where(r => r.Id.Kind == "youtube#video").Take(3)) { string fullVideoUrl = string.Empty; string videoId = string.Empty; string description = string.Empty; if (string.IsNullOrEmpty(result.Snippet.Description)) { description = "No description available."; } else { description = result.Snippet.Description; } if (result.Id.VideoId != null) { fullVideoUrl = $"{videoUrlPrefix}{result.Id.VideoId.ToString()}"; } sb.AppendLine($":video_camera: **__{result.Snippet.ChannelTitle}__** -> [**{result.Snippet.Title}**]({fullVideoUrl})\n\n *{description}*\n"); } embed.Description = sb.ToString(); await _channelServices.Reply(Context, embed); } }
public async Task ChangeGreeting([Remainder] string args = null) { var embed = new EmbedBuilder(); StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(args)) { embed.Title = $"Join greeting change for {Context.Guild.Name}"; sb.AppendLine("New message:"); sb.AppendLine(args); using (var db = new DiscbotContext()) { try { var guildGreetingInfo = db.ServerGreetings.AsEnumerable().Where(g => g.DiscordGuildId == (long)Context.Guild.Id).FirstOrDefault(); if (guildGreetingInfo != null) { guildGreetingInfo.Greeting = args.Trim(); guildGreetingInfo.SetById = (long)Context.User.Id; guildGreetingInfo.SetByName = Context.User.Username; guildGreetingInfo.TimeSet = DateTime.Now; } else { db.ServerGreetings.Add(new ServerGreeting { DiscordGuildId = (long)Context.Guild.Id, Greeting = args.Trim(), SetById = (long)Context.User.Id, SetByName = Context.User.Username, TimeSet = DateTime.Now }); } await db.SaveChangesAsync(); } catch (Exception) { embed.Title = $"Error changing message"; sb.AppendLine($"{Context.User.Mention},"); sb.AppendLine($"I've encounted an error, please contact the owner for help."); } } } else { embed.Title = $"Error changing message"; sb.AppendLine($"{Context.User.Mention},"); sb.AppendLine($"Please provided a message!"); } embed.Description = sb.ToString(); embed.WithColor(new Color(0, 255, 0)); embed.ThumbnailUrl = Context.Guild.IconUrl; await _channelServices.Reply(Context, embed); }
public async Task Giph([Remainder] string args = "") { bool isEnabled = CheckGiphyEnabled(Context); var embed = new EmbedBuilder(); embed.WithColor(new Color(0, 255, 255)); if (isEnabled) { StringBuilder sb = new StringBuilder(); GiphyResponses r = new GiphyResponses(); try { if (string.IsNullOrEmpty(args)) { r = _api.GetRandomImage(string.Empty); embed.Title = $"__Giphy for [**{Context.User.Username}**]__"; } else { r = _api.GetRandomImage(args); embed.Title = $"__Giphy for [**{Context.User.Username}**] ({args})__"; } embed.ImageUrl = r.data.fixed_height_small_url; await _channelServices.Reply(Context, embed); } catch (Exception ex) { await _channelServices.Reply(Context, "Sorry, something went wrong :("); Console.WriteLine($"Giphy Command Error -> [{ex.Message}]"); } } else { embed.Title = $"Sorry, Giphy is disabled here :(\n"; embed.Description = $"Use {_prefix}giphy-toggle to enable it"; await _channelServices.Reply(Context, embed); } }
public async Task SetAway([Remainder] string input) { try { StringBuilder sb = new StringBuilder(); var message = input; var user = Context.User; string userName = string.Empty; string userMentionName = string.Empty; if (user != null) { userName = user.Username; userMentionName = user.Mention; } var data = new AwayServices(); var away = new AwaySystem(); var attempt = data.GetAwayUser(userName); if (string.IsNullOrEmpty(message.ToString())) { message = "No message set!"; } if (attempt != null) { away.UserName = attempt.UserName; away.Status = attempt.Status; if ((bool)away.Status) { sb.AppendLine($"You're already away, **{userMentionName}**!"); } else { sb.AppendLine($"Marking you as away, **{userMentionName}**, with the message: *{message.ToString()}*"); away.Status = true; away.Message = message; away.UserName = userName; away.TimeAway = DateTime.Now; var awayData = new AwayServices(); awayData.SetAwayUser(away); } } else { sb.AppendLine($"Marking you as away, **{userMentionName}**, with the message: *{message.ToString()}*"); away.Status = true; away.Message = message; away.UserName = userName; away.TimeAway = DateTime.Now; var awayData = new AwayServices(); awayData.SetAwayUser(away); } await _channelServices.Reply(Context, sb.ToString()); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Something went wrong setting you away :("); _logger.LogError($"Away command error {ex.Message}"); await _channelServices.Reply(Context, sb.ToString()); } }
public async Task DefineWord([Remainder] string args) { StringBuilder sb = new StringBuilder(); var embed = new EmbedBuilder(); embed.WithColor(new Color(0, 255, 0)); embed.ThumbnailUrl = Context.User.GetAvatarUrl(); var result = _oxApi.SearchOxford(args); OxfordResponses.OxfordDefinition definition = null; int limit = 2; if (result.metadata.total > 0) { definition = _oxApi.DefineOxford(result.results[0].id); } if (definition != null) { Console.WriteLine(definition.results[0].lexicalEntries.Count()); embed.Title = $"Definition for: **{definition.results[0].id}**"; for (int i = 0; i <= definition.results[0].lexicalEntries.Count() - 1 && i < limit; i++) { var entries = definition.results[0].lexicalEntries[i].entries.FirstOrDefault(); if (entries.senses != null) { var senses = definition.results[0].lexicalEntries[i].entries[0].senses.FirstOrDefault(); sb.AppendLine($"**{definition.results[0].lexicalEntries[i].lexicalCategory}**"); if (senses.definitions != null) { sb.AppendLine($"{senses.definitions[0]}\n"); } else if (senses.crossReferenceMarkers != null) { sb.AppendLine($"{senses.crossReferenceMarkers[0]}"); } else { sb.AppendLine($"No definition found :(\n"); } } else { sb.AppendLine($"{definition.results[0].lexicalEntries[0].derivativeOf[0].text}"); break; } } var lexicalEntries = definition.results[0].lexicalEntries.FirstOrDefault(); if (lexicalEntries.pronunciations != null) { sb.AppendLine($"[Pronunciation]({lexicalEntries.pronunciations[0].audioFile})"); } //await ReplyAsync(, isTTS: true); } else { embed.Title = $"Definition for: **{args}**"; sb.AppendLine($"No definition found :("); } embed.Description = sb.ToString(); await _channelServices.Reply(Context, embed); }
public async Task ListGuilds() { StringBuilder sb = new StringBuilder(); var guilds = CommandHandler._client.Guilds.ToList(); foreach (var guild in guilds) { sb.AppendLine($"Name: {guild.Name} Id: {guild.Id} Owner: {guild.Owner}"); } await _channelServices.Reply(Context, sb.ToString()); }