youtube, welcome messages and futher code improvements
This commit is contained in:
parent
8d838eaae1
commit
59d0a5e135
7 changed files with 132 additions and 12 deletions
|
@ -7,6 +7,9 @@
|
||||||
<PackageReference Include="Discord.Net">
|
<PackageReference Include="Discord.Net">
|
||||||
<Version>1.0.0-rc</Version>
|
<Version>1.0.0-rc</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Google.Apis.YouTube.v3">
|
||||||
|
<Version>1.25.0.760</Version>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="RestSharp.NetCore">
|
<PackageReference Include="RestSharp.NetCore">
|
||||||
<Version>105.2.4-rc4-24214-01</Version>
|
<Version>105.2.4-rc4-24214-01</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|
16
Geekbot.net/Lib/BootTasks.cs
Normal file
16
Geekbot.net/Lib/BootTasks.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Geekbot.net.Modules;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib
|
||||||
|
{
|
||||||
|
public class BootTasks
|
||||||
|
{
|
||||||
|
public static async Task CheckSettingsFile()
|
||||||
|
{
|
||||||
|
// ToDO: Check settings file, if invalid, reconfig it
|
||||||
|
// Console.WriteLine(Path.GetFullPath("./settings.json"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,46 @@ using StackExchange.Redis;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// public class RedisClient
|
||||||
|
// {
|
||||||
|
// private static readonly Lazy<RedisClient> _instance
|
||||||
|
// = new Lazy<RedisClient>(() => new RedisClient());
|
||||||
|
// private static readonly object ThreadLock = new object();
|
||||||
|
// public static IDatabase Client;
|
||||||
|
//
|
||||||
|
// private RedisClient()
|
||||||
|
// { }
|
||||||
|
//
|
||||||
|
// public static RedisClient Instance
|
||||||
|
// {
|
||||||
|
// get
|
||||||
|
// {
|
||||||
|
// if (_instance.IsValueCreated)
|
||||||
|
// {
|
||||||
|
// return _instance.Value;
|
||||||
|
// }
|
||||||
|
// lock (ThreadLock)
|
||||||
|
// {
|
||||||
|
// if (Client == null)
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
||||||
|
// Client = redis.GetDatabase();
|
||||||
|
// }
|
||||||
|
// catch (Exception)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine("Start Reids already you fucking faggot!");
|
||||||
|
// Environment.Exit(69);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return _instance.Value;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public interface IRedisClient
|
public interface IRedisClient
|
||||||
{
|
{
|
||||||
IDatabase Client { get; set; }
|
IDatabase Client { get; set; }
|
||||||
|
@ -12,12 +52,16 @@ namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
public RedisClient()
|
public RedisClient()
|
||||||
{
|
{
|
||||||
var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
try
|
||||||
if (!redis.IsConnected)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("Could not Connect to the Server...");
|
var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
|
||||||
|
Client = redis.GetDatabase();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Start Redis already you fucking faggot!");
|
||||||
|
Environment.Exit(69);
|
||||||
}
|
}
|
||||||
Client = redis.GetDatabase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDatabase Client { get; set; }
|
public IDatabase Client { get; set; }
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace Geekbot.net.Lib
|
||||||
var key = guildId + "-" + message.Author.Id + "-messages";
|
var key = guildId + "-" + message.Author.Id + "-messages";
|
||||||
var messages = (int)redis.StringGet(key);
|
var messages = (int)redis.StringGet(key);
|
||||||
redis.StringSet(key, (messages + 1).ToString());
|
redis.StringSet(key, (messages + 1).ToString());
|
||||||
await Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateGuildRecordAsync()
|
public async Task UpdateGuildRecordAsync()
|
||||||
|
@ -32,7 +31,6 @@ namespace Geekbot.net.Lib
|
||||||
var key = guildId + "-messages";
|
var key = guildId + "-messages";
|
||||||
var messages = (int)redis.StringGet(key);
|
var messages = (int)redis.StringGet(key);
|
||||||
redis.StringSet(key, (messages + 1).ToString());
|
redis.StringSet(key, (messages + 1).ToString());
|
||||||
await Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,12 +21,26 @@ namespace Geekbot.net.Modules
|
||||||
var messages = (int)redis.StringGet(key);
|
var messages = (int)redis.StringGet(key);
|
||||||
var level = GetLevelAtExperience(messages);
|
var level = GetLevelAtExperience(messages);
|
||||||
|
|
||||||
await ReplyAsync($"```\r\n" +
|
var reply = "";
|
||||||
$"{userInfo.Username}#{userInfo.Discriminator}\r\n" +
|
|
||||||
$"Messages Sent: {messages}\r\n" +
|
if (Context.Message.Author.Id == userInfo.Id)
|
||||||
$"Level: {level}\r\n" +
|
{
|
||||||
$"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)" +
|
reply = reply + $"here are your stats {userInfo.Mention}\r\n";
|
||||||
$"```");
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reply = reply + $"here are {userInfo.Mention}'s stats\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
reply = reply + $"```\r\n";
|
||||||
|
reply = reply + $"Level: {level}\r\n";
|
||||||
|
reply = reply + $"Messages Sent: {messages}\r\n";
|
||||||
|
reply =
|
||||||
|
reply +
|
||||||
|
$"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)";
|
||||||
|
reply = reply + $"```";
|
||||||
|
|
||||||
|
await ReplyAsync(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("level"), Summary("Get a level based on a number")]
|
[Command("level"), Summary("Get a level based on a number")]
|
||||||
|
|
42
Geekbot.net/Modules/Youtube.cs
Normal file
42
Geekbot.net/Modules/Youtube.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
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 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
|
||||||
|
{
|
||||||
|
[Command("yt"), Summary("Search for something on youtube.")]
|
||||||
|
public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery)
|
||||||
|
{
|
||||||
|
// AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E
|
||||||
|
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||||
|
{
|
||||||
|
ApiKey = "AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E",
|
||||||
|
ApplicationName = this.GetType().ToString()
|
||||||
|
});
|
||||||
|
|
||||||
|
var searchListRequest = youtubeService.Search.List("snippet");
|
||||||
|
searchListRequest.Q = searchQuery; // Replace with your search term.
|
||||||
|
searchListRequest.MaxResults = 50;
|
||||||
|
|
||||||
|
// 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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,9 @@ namespace Geekbot.net
|
||||||
Console.WriteLine(" \\____|_____|_____|_|\\_\\____/ \\___/ |_|");
|
Console.WriteLine(" \\____|_____|_____|_|\\_\\____/ \\___/ |_|");
|
||||||
Console.WriteLine("=========================================");
|
Console.WriteLine("=========================================");
|
||||||
Console.WriteLine("Starting...");
|
Console.WriteLine("Starting...");
|
||||||
|
|
||||||
|
// Task.WaitAll(BootTasks.CheckSettingsFile());
|
||||||
|
|
||||||
Task.WaitAll(new Program().MainAsync());
|
Task.WaitAll(new Program().MainAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue