removed youtube api key from the repo
This commit is contained in:
parent
cb8423373a
commit
f46e1b6071
2 changed files with 49 additions and 20 deletions
|
@ -23,5 +23,19 @@ namespace Geekbot.net.Modules
|
|||
await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
|
||||
formatedMessage);
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async), Summary("Set the youtube api key")]
|
||||
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
||||
{
|
||||
var botOwner = redis.Client.StringGet("botOwner");
|
||||
if (!Context.User.Id.ToString().Equals(botOwner.ToString()))
|
||||
{
|
||||
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner}");
|
||||
return;
|
||||
}
|
||||
|
||||
redis.Client.StringSet("youtubeKey", key);
|
||||
await ReplyAsync("Apikey has been set");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,56 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Geekbot.net.Lib;
|
||||
using Google.Apis.Services;
|
||||
using Google.Apis.Upload;
|
||||
using Google.Apis.Util.Store;
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Youtube : ModuleBase
|
||||
{
|
||||
private readonly IRedisClient redis;
|
||||
public Youtube(IRedisClient redisClient)
|
||||
{
|
||||
redis = redisClient;
|
||||
}
|
||||
|
||||
[Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||
{
|
||||
var key = redis.Client.StringGet("youtubeKey");
|
||||
if (key.IsNullOrEmpty)
|
||||
{
|
||||
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = "AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E",
|
||||
ApiKey = key.ToString(),
|
||||
ApplicationName = this.GetType().ToString()
|
||||
});
|
||||
|
||||
var searchListRequest = youtubeService.Search.List("snippet");
|
||||
searchListRequest.Q = searchQuery; // Replace with your search term.
|
||||
searchListRequest.MaxResults = 50;
|
||||
searchListRequest.Q = searchQuery;
|
||||
searchListRequest.MaxResults = 2;
|
||||
|
||||
// Call the search.list method to retrieve results matching the specified query term.
|
||||
var searchListResponse = await searchListRequest.ExecuteAsync();
|
||||
|
||||
var result = searchListResponse.Items[0];
|
||||
|
||||
await ReplyAsync($"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
||||
await ReplyAsync(
|
||||
$"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ReplyAsync("Something went wrong... informing my senpai...");
|
||||
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.Client.StringGet("botOwner"))).Result;
|
||||
var dm = await botOwner.CreateDMChannelAsync();
|
||||
await dm.SendMessageAsync($"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue