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" +
|
await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
|
||||||
formatedMessage);
|
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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Google.Apis.Auth.OAuth2;
|
|
||||||
using Google.Apis.Services;
|
using Google.Apis.Services;
|
||||||
using Google.Apis.Upload;
|
|
||||||
using Google.Apis.Util.Store;
|
|
||||||
using Google.Apis.YouTube.v3;
|
using Google.Apis.YouTube.v3;
|
||||||
using Google.Apis.YouTube.v3.Data;
|
|
||||||
|
|
||||||
namespace Geekbot.net.Modules
|
namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class Youtube : ModuleBase
|
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.")]
|
[Command("yt", RunMode = RunMode.Async), Summary("Search for something on youtube.")]
|
||||||
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||||
{
|
{
|
||||||
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
var key = redis.Client.StringGet("youtubeKey");
|
||||||
|
if (key.IsNullOrEmpty)
|
||||||
{
|
{
|
||||||
ApiKey = "AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E",
|
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||||
ApplicationName = this.GetType().ToString()
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
var searchListRequest = youtubeService.Search.List("snippet");
|
try
|
||||||
searchListRequest.Q = searchQuery; // Replace with your search term.
|
{
|
||||||
searchListRequest.MaxResults = 50;
|
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||||
|
{
|
||||||
|
ApiKey = key.ToString(),
|
||||||
|
ApplicationName = this.GetType().ToString()
|
||||||
|
});
|
||||||
|
|
||||||
// Call the search.list method to retrieve results matching the specified query term.
|
var searchListRequest = youtubeService.Search.List("snippet");
|
||||||
var searchListResponse = await searchListRequest.ExecuteAsync();
|
searchListRequest.Q = searchQuery;
|
||||||
|
searchListRequest.MaxResults = 2;
|
||||||
|
|
||||||
var result = searchListResponse.Items[0];
|
var searchListResponse = await searchListRequest.ExecuteAsync();
|
||||||
|
|
||||||
await ReplyAsync($"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}");
|
var result = searchListResponse.Items[0];
|
||||||
|
|
||||||
|
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