fixed ~ani and ~mang
This commit is contained in:
parent
ffb63f9e81
commit
4c0e832463
@ -13,8 +13,8 @@ namespace NadekoBot {
|
|||||||
|
|
||||||
public string BotVersion => $"{Assembly.GetExecutingAssembly().GetName().Name} v{Assembly.GetExecutingAssembly().GetName().Version}";
|
public string BotVersion => $"{Assembly.GetExecutingAssembly().GetName().Name} v{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||||
|
|
||||||
private int _commandsRan = 0;
|
private int commandsRan = 0;
|
||||||
private string _statsCache = "";
|
private string statsCache = "";
|
||||||
private readonly Stopwatch statsStopwatch = new Stopwatch();
|
private readonly Stopwatch statsStopwatch = new Stopwatch();
|
||||||
|
|
||||||
public int ServerCount { get; private set; } = 0;
|
public int ServerCount { get; private set; } = 0;
|
||||||
@ -98,19 +98,19 @@ namespace NadekoBot {
|
|||||||
sb.Append($"`Servers: {ServerCount}");
|
sb.Append($"`Servers: {ServerCount}");
|
||||||
sb.Append($" | TextChannels: {TextChannelsCount}");
|
sb.Append($" | TextChannels: {TextChannelsCount}");
|
||||||
sb.AppendLine($" | VoiceChannels: {VoiceChannelsCount}`");
|
sb.AppendLine($" | VoiceChannels: {VoiceChannelsCount}`");
|
||||||
sb.AppendLine($"`Commands Ran this session: {_commandsRan}`");
|
sb.AppendLine($"`Commands Ran this session: {commandsRan}`");
|
||||||
sb.AppendLine($"`Message queue size:{NadekoBot.Client.MessageQueue.Count}`");
|
sb.AppendLine($"`Message queue size:{NadekoBot.Client.MessageQueue.Count}`");
|
||||||
sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`");
|
sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`");
|
||||||
_statsCache = sb.ToString();
|
statsCache = sb.ToString();
|
||||||
});
|
});
|
||||||
|
|
||||||
public string Heap() => Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString();
|
public string Heap() => Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString();
|
||||||
|
|
||||||
public async Task<string> GetStats() {
|
public async Task<string> GetStats() {
|
||||||
if (statsStopwatch.Elapsed.Seconds <= 5) return _statsCache;
|
if (statsStopwatch.Elapsed.Seconds <= 5) return statsCache;
|
||||||
await LoadStats();
|
await LoadStats();
|
||||||
statsStopwatch.Restart();
|
statsStopwatch.Restart();
|
||||||
return _statsCache;
|
return statsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StartCollecting() {
|
private async Task StartCollecting() {
|
||||||
@ -136,10 +136,11 @@ namespace NadekoBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//todo - batch save this
|
|
||||||
private void StatsCollector_RanCommand(object sender, CommandEventArgs e) {
|
private async void StatsCollector_RanCommand(object sender, CommandEventArgs e) {
|
||||||
|
await Task.Run(() => {
|
||||||
try {
|
try {
|
||||||
_commandsRan++;
|
commandsRan++;
|
||||||
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command {
|
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command {
|
||||||
ServerId = (long) e.Server.Id,
|
ServerId = (long) e.Server.Id,
|
||||||
ServerName = e.Server.Name,
|
ServerName = e.Server.Name,
|
||||||
@ -154,6 +155,7 @@ namespace NadekoBot {
|
|||||||
catch {
|
catch {
|
||||||
Console.WriteLine("Error in ran command DB write.");
|
Console.WriteLine("Error in ran command DB write.");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -56,40 +57,44 @@ namespace NadekoBot.Classes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<AnimeResult> GetAnimeQueryResultLink(string query) {
|
public static async Task<AnimeResult> GetAnimeData(string query) {
|
||||||
if (string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
|
||||||
await RefreshAnilistToken();
|
await RefreshAnilistToken();
|
||||||
|
|
||||||
var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
||||||
try {
|
var smallContent = "";
|
||||||
var headers = new Dictionary<string, string> {{"'access_token'", "'"+token+"'"}};
|
var cl = new RestSharp.RestClient("http://anilist.co/api");
|
||||||
var smallContent = await GetResponseStringAsync(link, headers);
|
var rq = new RestSharp.RestRequest("/anime/search/" + Uri.EscapeUriString(query));
|
||||||
|
rq.AddParameter("access_token", token);
|
||||||
|
smallContent = cl.Execute(rq).Content;
|
||||||
var smallObj = JArray.Parse(smallContent)[0];
|
var smallObj = JArray.Parse(smallContent)[0];
|
||||||
var content = await GetResponseStringAsync("http://anilist.co/api/anime/" + smallObj["id"], headers);
|
|
||||||
|
rq = new RestSharp.RestRequest("/anime/" + smallObj["id"]);
|
||||||
|
rq.AddParameter("access_token", token);
|
||||||
|
var content = cl.Execute(rq).Content;
|
||||||
|
|
||||||
return await Task.Run(() => JsonConvert.DeserializeObject<AnimeResult>(content));
|
return await Task.Run(() => JsonConvert.DeserializeObject<AnimeResult>(content));
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Console.WriteLine(ex);
|
|
||||||
return new AnimeResult();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<MangaResult> GetMangaQueryResultLink(string query) {
|
public static async Task<MangaResult> GetMangaData(string query) {
|
||||||
if (string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
|
||||||
await RefreshAnilistToken();
|
await RefreshAnilistToken();
|
||||||
|
|
||||||
var link = "http://anilist.co/api/manga/search/" + Uri.EscapeUriString(query);
|
var link = "http://anilist.co/api/anime/search/" + Uri.EscapeUriString(query);
|
||||||
|
var smallContent = "";
|
||||||
var headers = new Dictionary<string, string> { { "access_token", token } };
|
var cl = new RestSharp.RestClient("http://anilist.co/api");
|
||||||
var smallContent = await GetResponseStringAsync(link, headers);
|
var rq = new RestSharp.RestRequest("/manga/search/" + Uri.EscapeUriString(query));
|
||||||
|
rq.AddParameter("access_token", token);
|
||||||
|
smallContent = cl.Execute(rq).Content;
|
||||||
var smallObj = JArray.Parse(smallContent)[0];
|
var smallObj = JArray.Parse(smallContent)[0];
|
||||||
var content = await GetResponseStringAsync("http://anilist.co/api/manga/" + smallObj["id"], headers);
|
|
||||||
|
rq = new RestSharp.RestRequest("/manga/" + smallObj["id"]);
|
||||||
|
rq.AddParameter("access_token", token);
|
||||||
|
var content = cl.Execute(rq).Content;
|
||||||
|
|
||||||
return await Task.Run(() => JsonConvert.DeserializeObject<MangaResult>(content));
|
return await Task.Run(() => JsonConvert.DeserializeObject<MangaResult>(content));
|
||||||
}
|
}
|
||||||
@ -144,10 +149,9 @@ namespace NadekoBot.Classes {
|
|||||||
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey))
|
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.GoogleAPIKey))
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
|
||||||
var link = $"https://www.googleapis.com/youtube/v3/search?part=snippet" +
|
var link = "https://www.googleapis.com/youtube/v3/search?part=snippet" +
|
||||||
$"&maxResults=1" +
|
"&maxResults=1&type=playlist" +
|
||||||
$"&q={Uri.EscapeDataString(query)}" +
|
$"&q={Uri.EscapeDataString(query)}" +
|
||||||
$"&type=playlist" +
|
|
||||||
$"&key={NadekoBot.Creds.GoogleAPIKey}";
|
$"&key={NadekoBot.Creds.GoogleAPIKey}";
|
||||||
|
|
||||||
var response = await GetResponseStringAsync(link);
|
var response = await GetResponseStringAsync(link);
|
||||||
|
@ -144,7 +144,6 @@ namespace NadekoBot.Commands {
|
|||||||
|
|
||||||
var orderArr = (data["skills"]["mostGames"]["order"] as JArray);
|
var orderArr = (data["skills"]["mostGames"]["order"] as JArray);
|
||||||
|
|
||||||
//todo save this for at least 1 hour
|
|
||||||
var img = Image.FromFile("data/lol/bg.png");
|
var img = Image.FromFile("data/lol/bg.png");
|
||||||
using (var g = Graphics.FromImage(img)) {
|
using (var g = Graphics.FromImage(img)) {
|
||||||
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||||
@ -162,7 +161,7 @@ namespace NadekoBot.Commands {
|
|||||||
champName = "Wukong";
|
champName = "Wukong";
|
||||||
g.DrawString($"{champName}", new Font("Times New Roman", 24, FontStyle.Regular), Brushes.WhiteSmoke, margin + imageSize + margin, margin);
|
g.DrawString($"{champName}", new Font("Times New Roman", 24, FontStyle.Regular), Brushes.WhiteSmoke, margin + imageSize + margin, margin);
|
||||||
//draw champ surname
|
//draw champ surname
|
||||||
//todo
|
|
||||||
//draw skill order
|
//draw skill order
|
||||||
float orderFormula = 120 / orderArr.Count;
|
float orderFormula = 120 / orderArr.Count;
|
||||||
const float orderVerticalSpacing = 10;
|
const float orderVerticalSpacing = 10;
|
||||||
|
@ -19,7 +19,7 @@ namespace NadekoBot.Commands {
|
|||||||
public string GetRequests() {
|
public string GetRequests() {
|
||||||
var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>();
|
var task = Classes.DbHandler.Instance.GetAllRows<Classes._DataModels.Request>();
|
||||||
|
|
||||||
string str = "Here are all current requests for NadekoBot:\n\n";
|
var str = "Here are all current requests for NadekoBot:\n\n";
|
||||||
foreach (var reqObj in task) {
|
foreach (var reqObj in task) {
|
||||||
str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" +
|
str += $"{reqObj.Id}. by **{reqObj.UserName}** from **{reqObj.ServerName}** at {reqObj.DateAdded.ToLocalTime()}\n" +
|
||||||
$"**{reqObj.RequestText}**\n----------\n";
|
$"**{reqObj.RequestText}**\n----------\n";
|
||||||
@ -48,7 +48,7 @@ namespace NadekoBot.Commands {
|
|||||||
.Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature")
|
.Description("Requests a feature for nadeko.\n**Usage**: @NadekoBot req new_feature")
|
||||||
.Parameter("all", ParameterType.Unparsed)
|
.Parameter("all", ParameterType.Unparsed)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
string str = e.Args[0];
|
var str = e.Args[0];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SaveRequest(e, str);
|
SaveRequest(e, str);
|
||||||
@ -62,7 +62,7 @@ namespace NadekoBot.Commands {
|
|||||||
cgb.CreateCommand("lr")
|
cgb.CreateCommand("lr")
|
||||||
.Description("PMs the user all current nadeko requests.")
|
.Description("PMs the user all current nadeko requests.")
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
string str = GetRequests();
|
var str = await Task.Run(() => GetRequests());
|
||||||
if (str.Trim().Length > 110)
|
if (str.Trim().Length > 110)
|
||||||
await e.User.Send(str);
|
await e.User.Send(str);
|
||||||
else
|
else
|
||||||
|
@ -44,7 +44,7 @@ namespace NadekoBot.Modules {
|
|||||||
if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
||||||
string result;
|
string result;
|
||||||
try {
|
try {
|
||||||
result = (await SearchHelper.GetAnimeQueryResultLink(e.GetArg("query"))).ToString();
|
result = (await SearchHelper.GetAnimeData(e.GetArg("query"))).ToString();
|
||||||
} catch {
|
} catch {
|
||||||
await e.Channel.SendMessage("Failed to find that anime.");
|
await e.Channel.SendMessage("Failed to find that anime.");
|
||||||
return;
|
return;
|
||||||
@ -61,7 +61,7 @@ namespace NadekoBot.Modules {
|
|||||||
if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
if (!(await SearchHelper.ValidateQuery(e.Channel, e.GetArg("query")))) return;
|
||||||
string result;
|
string result;
|
||||||
try {
|
try {
|
||||||
result = (await SearchHelper.GetMangaQueryResultLink(e.GetArg("query"))).ToString();
|
result = (await SearchHelper.GetMangaData(e.GetArg("query"))).ToString();
|
||||||
} catch {
|
} catch {
|
||||||
await e.Channel.SendMessage("Failed to find that anime.");
|
await e.Channel.SendMessage("Failed to find that anime.");
|
||||||
return;
|
return;
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user