Prettified whole searches module

This commit is contained in:
Kwoth 2016-12-09 04:22:23 +01:00
parent 19bd02dbbb
commit 010c679a76
14 changed files with 155 additions and 164 deletions

View File

@ -29,19 +29,25 @@ namespace NadekoBot.Modules.Searches
_log = LogManager.GetCurrentClassLogger();
anilistTokenRefresher = new Timer(async (state) =>
{
var headers = new Dictionary<string, string> {
{"grant_type", "client_credentials"},
{"client_id", "kwoth-w0ki9"},
{"client_secret", "Qd6j4FIAi1ZK6Pc7N7V4Z"},
};
using (var http = new HttpClient())
try
{
http.AddFakeHeaders();
var formContent = new FormUrlEncodedContent(headers);
var response = await http.PostAsync("http://anilist.co/api/auth/access_token", formContent).ConfigureAwait(false);
var stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
anilistToken = JObject.Parse(stringContent)["access_token"].ToString();
var headers = new Dictionary<string, string> {
{"grant_type", "client_credentials"},
{"client_id", "kwoth-w0ki9"},
{"client_secret", "Qd6j4FIAi1ZK6Pc7N7V4Z"},
};
using (var http = new HttpClient())
{
http.AddFakeHeaders();
var formContent = new FormUrlEncodedContent(headers);
var response = await http.PostAsync("http://anilist.co/api/auth/access_token", formContent).ConfigureAwait(false);
var stringContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
anilistToken = JObject.Parse(stringContent)["access_token"].ToString();
}
}
catch (Exception ex) {
_log.Error(ex);
}
}, null, TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(29));
}
@ -57,6 +63,12 @@ namespace NadekoBot.Modules.Searches
var animeData = await GetAnimeData(query).ConfigureAwait(false);
if (animeData == null)
{
await umsg.Channel.SendErrorAsync("Failed finding that animu.").ConfigureAwait(false);
return;
}
var embed = new Discord.API.Embed()
{
Description = animeData.Synopsis,
@ -96,32 +108,38 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(query))
return;
var animeData = await GetMangaData(query).ConfigureAwait(false);
var mangaData = await GetMangaData(query).ConfigureAwait(false);
if (mangaData == null)
{
await umsg.Channel.SendErrorAsync("Failed finding that mango.").ConfigureAwait(false);
return;
}
var embed = new Discord.API.Embed()
{
Description = animeData.Synopsis,
Title = animeData.title_english,
Url = animeData.Link,
Description = mangaData.Synopsis,
Title = mangaData.title_english,
Url = mangaData.Link,
Image = new Discord.API.EmbedImage()
{
Url = animeData.image_url_lge
Url = mangaData.image_url_lge
},
Fields = new[] {
new Discord.API.EmbedField() {
Inline = true,
Name = "Chapters",
Value = animeData.total_chapters.ToString()
Value = mangaData.total_chapters.ToString()
},
new Discord.API.EmbedField() {
Inline = true,
Name = "Status",
Value = animeData.publishing_status.ToString()
Value = mangaData.publishing_status.ToString()
},
new Discord.API.EmbedField() {
Inline = true,
Name = "Genres",
Value = String.Join(", ", animeData.Genres)
Value = String.Join(", ", mangaData.Genres)
}
},
Color = NadekoBot.OkColor

View File

@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules.Searches.Models;
using NadekoBot.Services;
using Newtonsoft.Json;
@ -19,9 +20,9 @@ namespace NadekoBot.Modules.Searches
[Group]
public class JokeCommands
{
private static List<WoWJoke> wowJokes = new List<WoWJoke>();
private static List<MagicItem> magicItems;
private static Logger _log;
private static List<WoWJoke> wowJokes { get; } = new List<WoWJoke>();
private static List<MagicItem> magicItems { get; } = new List<MagicItem>();
private static Logger _log { get; }
static JokeCommands()
{
@ -43,61 +44,62 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Yomama(IUserMessage umsg)
public async Task Yomama(IUserMessage msg)
{
var channel = (ITextChannel)umsg.Channel;
using (var http = new HttpClient())
{
var response = await http.GetStringAsync("http://api.yomomma.info/").ConfigureAwait(false);
await channel.SendMessageAsync("`" + JObject.Parse(response)["joke"].ToString() + "` 😆").ConfigureAwait(false);
await msg.Channel.SendConfirmAsync(JObject.Parse(response)["joke"].ToString() + " 😆").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Randjoke(IUserMessage umsg)
public async Task Randjoke(IUserMessage msg)
{
var channel = (ITextChannel)umsg.Channel;
using (var http = new HttpClient())
{
var response = await http.GetStringAsync("http://tambal.azurewebsites.net/joke/random").ConfigureAwait(false);
await channel.SendMessageAsync("`" + JObject.Parse(response)["joke"].ToString() + "` 😆").ConfigureAwait(false);
await msg.Channel.SendConfirmAsync(JObject.Parse(response)["joke"].ToString() + " 😆").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ChuckNorris(IUserMessage umsg)
public async Task ChuckNorris(IUserMessage msg)
{
var channel = (ITextChannel)umsg.Channel;
using (var http = new HttpClient())
{
var response = await http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false);
await channel.SendMessageAsync("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆").ConfigureAwait(false);
await msg.Channel.SendConfirmAsync(JObject.Parse(response)["value"]["joke"].ToString() + " 😆").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task WowJoke(IUserMessage umsg)
public async Task WowJoke(IUserMessage msg)
{
var channel = (ITextChannel)umsg.Channel;
if (!wowJokes.Any())
{
await msg.Channel.SendErrorAsync("Jokes not loaded.").ConfigureAwait(false);
return;
}
await channel.SendMessageAsync(wowJokes[new NadekoRandom().Next(0, wowJokes.Count)].ToString());
var joke = wowJokes[new NadekoRandom().Next(0, wowJokes.Count)];
await msg.Channel.SendConfirmAsync(joke.Question, joke.Answer).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task MagicItem(IUserMessage umsg)
public async Task MagicItem(IUserMessage msg)
{
var channel = (ITextChannel)umsg.Channel;
var rng = new NadekoRandom();
var item = magicItems[rng.Next(0, magicItems.Count)].ToString();
if (!wowJokes.Any())
{
await msg.Channel.SendErrorAsync("MagicItems not loaded.").ConfigureAwait(false);
return;
}
var item = magicItems[new NadekoRandom().Next(0, magicItems.Count)];
await channel.SendMessageAsync(item).ConfigureAwait(false);
await msg.Channel.SendConfirmAsync("✨" + item.Name, item.Description).ConfigureAwait(false);
}
}
}

View File

@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using Newtonsoft.Json.Linq;
using System;
@ -50,23 +51,19 @@ namespace NadekoBot.Modules.Searches
$"limit={showCount}")
.ConfigureAwait(false))["data"] as JArray;
var dataList = data.Distinct(new ChampionNameComparer()).Take(showCount).ToList();
var sb = new StringBuilder();
sb.AppendLine($"**Showing {dataList.Count} top banned champions.**");
sb.AppendLine($"`{trashTalk[new NadekoRandom().Next(0, trashTalk.Length)]}`");
var eb = new EmbedBuilder().WithColor(NadekoBot.OkColor).WithTitle(Format.Underline($"{dataList.Count} most banned champions"));
for (var i = 0; i < dataList.Count; i++)
{
if (i % 2 == 0 && i != 0)
sb.AppendLine();
sb.Append($"`{i + 1}.` **{dataList[i]["name"]}** {dataList[i]["general"]["banRate"]}% ");
//sb.AppendLine($" ({dataList[i]["general"]["banRate"]}%)");
var champ = dataList[i];
eb.AddField(efb => efb.WithName(champ["name"].ToString()).WithValue(champ["general"]["banRate"] + "%").WithIsInline(true));
}
await channel.SendMessageAsync(sb.ToString()).ConfigureAwait(false);
await channel.EmbedAsync(eb.Build(), Format.Italics(trashTalk[new NadekoRandom().Next(0, trashTalk.Length)])).ConfigureAwait(false);
}
}
catch (Exception)
{
await channel.SendMessageAsync($":anger: `Something went wrong.`").ConfigureAwait(false);
await channel.SendMessageAsync("Something went wrong.").ConfigureAwait(false);
}
}
}

View File

@ -25,20 +25,11 @@ namespace NadekoBot.Modules.Searches
using (var http = new HttpClient(handler))
{
http.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
string rawJson = "";
try
{
rawJson = await http.GetStringAsync("https://memegen.link/api/templates/").ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
var rawJson = await http.GetStringAsync("https://memegen.link/api/templates/").ConfigureAwait(false);
var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson)
.Select(kvp => Path.GetFileName(kvp.Value));
.Select(kvp => Path.GetFileName(kvp.Value));
await channel.SendTableAsync(data, x => $"{x,-17}", 3);
await channel.SendTableAsync(data, x => $"{x,-17}", 3).ConfigureAwait(false);
}
}
@ -50,7 +41,8 @@ namespace NadekoBot.Modules.Searches
var top = Uri.EscapeDataString(topText.Replace(' ', '-'));
var bot = Uri.EscapeDataString(botText.Replace(' ', '-'));
await channel.SendMessageAsync($"http://memegen.link/{meme}/{top}/{bot}.jpg");
await channel.SendMessageAsync($"http://memegen.link/{meme}/{top}/{bot}.jpg")
.ConfigureAwait(false);
}
}
}

View File

@ -4,7 +4,5 @@
{
public string Name { get; set; }
public string Description { get; set; }
public override string ToString() =>
$"✨`{Name}`\n\t*{Description}*";
}
}

View File

@ -18,9 +18,8 @@ namespace NadekoBot.Modules.Searches.Models
public int SPD { get; set; }
public int SPE { get; set; }
public override string ToString() => $@"
**HP:** {HP,-4} **ATK:** {ATK,-4} **DEF:** {DEF,-4}
**SPA:** {SPA,-4} **SPD:** {SPD,-4} **SPE:** {SPE,-4}";
public override string ToString() => $@"**HP:** {HP,-4} **ATK:** {ATK,-4} **DEF:** {DEF,-4}
**SPA:** {SPA,-4} **SPD:** {SPD,-4} **SPE:** {SPE,-4}";
}
public int Id { get; set; }
public string Species { get; set; }

View File

@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Searches
[Group]
public class OsuCommands
{
private static Logger _log;
private static Logger _log { get; }
static OsuCommands()
{
@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Searches
}
catch (Exception ex)
{
await channel.SendMessageAsync("💢 Failed retrieving osu signature :\\").ConfigureAwait(false);
await channel.SendErrorAsync("Failed retrieving osu signature.").ConfigureAwait(false);
_log.Warn(ex, "Osu command failed");
}
}
@ -66,7 +66,7 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.OsuApiKey))
{
await channel.SendMessageAsync("💢 An osu! API key is required.").ConfigureAwait(false);
await channel.SendErrorAsync("An osu! API key is required.").ConfigureAwait(false);
return;
}
@ -90,7 +90,7 @@ namespace NadekoBot.Modules.Searches
}
catch (Exception ex)
{
await channel.SendMessageAsync("Something went wrong.");
await channel.SendErrorAsync("Something went wrong.");
_log.Warn(ex, "Osub command failed");
}
}
@ -102,13 +102,13 @@ namespace NadekoBot.Modules.Searches
var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.OsuApiKey))
{
await channel.SendMessageAsync("💢 An osu! API key is required.").ConfigureAwait(false);
await channel.SendErrorAsync("An osu! API key is required.").ConfigureAwait(false);
return;
}
if (string.IsNullOrWhiteSpace(user))
{
await channel.SendMessageAsync("💢 Please provide a username.").ConfigureAwait(false);
await channel.SendErrorAsync("Please provide a username.").ConfigureAwait(false);
return;
}
using (var http = new HttpClient())
@ -141,7 +141,7 @@ namespace NadekoBot.Modules.Searches
}
catch (Exception ex)
{
await channel.SendMessageAsync("Something went wrong.");
await channel.SendErrorAsync("Something went wrong.");
_log.Warn(ex, "Osu5 command failed");
}

View File

@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using System;
using System.Threading.Tasks;
@ -36,7 +37,7 @@ namespace NadekoBot.Modules.Searches
{
var channel = (ITextChannel)imsg.Channel;
await channel.SendMessageAsync(typesStr)
await channel.SendConfirmAsync(typesStr)
.ConfigureAwait(false);
}

View File

@ -1,11 +1,13 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules.Searches.Models;
using Newtonsoft.Json;
using NLog;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Searches
@ -15,13 +17,13 @@ namespace NadekoBot.Modules.Searches
[Group]
public class PokemonSearchCommands
{
private static Dictionary<string, SearchPokemon> pokemons = new Dictionary<string, SearchPokemon>();
private static Dictionary<string, SearchPokemonAbility> pokemonAbilities = new Dictionary<string, SearchPokemonAbility>();
private static Dictionary<string, SearchPokemon> pokemons { get; } = new Dictionary<string, SearchPokemon>();
private static Dictionary<string, SearchPokemonAbility> pokemonAbilities { get; } = new Dictionary<string, SearchPokemonAbility>();
public const string PokemonAbilitiesFile = "data/pokemon/pokemon_abilities.json";
public const string PokemonListFile = "data/pokemon/pokemon_list.json";
private static Logger _log;
private static Logger _log { get; }
static PokemonSearchCommands()
{
@ -52,11 +54,18 @@ namespace NadekoBot.Modules.Searches
{
if (kvp.Key.ToUpperInvariant() == pokemon.ToUpperInvariant())
{
await channel.SendMessageAsync($"`Stats for \"{kvp.Key}\" pokemon:`\n{kvp.Value}");
var p = kvp.Value;
await channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithTitle(kvp.Key.ToTitleCase())
.WithDescription(p.BaseStats.ToString())
.AddField(efb => efb.WithName("Types").WithValue(string.Join(",\n", p.Types)).WithIsInline(true))
.AddField(efb => efb.WithName("Height/Weight").WithValue($"{p.HeightM}m/{p.WeightKg}kg").WithIsInline(true))
.AddField(efb => efb.WithName("Abilitities").WithValue(string.Join(",\n", p.Abilities.Select(a => a.Value))).WithIsInline(true))
.Build());
return;
}
}
await channel.SendMessageAsync("`No pokemon found.`");
await channel.SendErrorAsync("No pokemon found.");
}
[NadekoCommand, Usage, Description, Aliases]
@ -72,11 +81,15 @@ namespace NadekoBot.Modules.Searches
{
if (kvp.Key.ToUpperInvariant() == ability)
{
await channel.SendMessageAsync($"`Info for \"{kvp.Key}\" ability:`\n{kvp.Value}");
await channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithTitle(kvp.Value.Name)
.WithDescription(kvp.Value.Desc)
.AddField(efb => efb.WithName("Rating").WithValue(kvp.Value.Rating.ToString()).WithIsInline(true))
.Build()).ConfigureAwait(false);
return;
}
}
await channel.SendMessageAsync("`No ability found.`");
await channel.SendErrorAsync("No ability found.");
}
}
}

View File

@ -91,28 +91,28 @@ namespace NadekoBot.Modules.Searches
}
await Task.WhenAll(streams.Select(async fs =>
{
try
{
var newStatus = await GetStreamStatus(fs).ConfigureAwait(false);
if (FirstPass)
{
return;
}
{
try
{
var newStatus = await GetStreamStatus(fs).ConfigureAwait(false);
if (FirstPass)
{
return;
}
StreamStatus oldStatus;
if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) &&
oldStatus.IsLive != newStatus.IsLive)
{
var server = NadekoBot.Client.GetGuild(fs.GuildId);
var channel = server?.GetTextChannel(fs.ChannelId);
if (channel == null)
return;
try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { }
}
}
catch { }
}));
StreamStatus oldStatus;
if (oldCachedStatuses.TryGetValue(newStatus.ApiLink, out oldStatus) &&
oldStatus.IsLive != newStatus.IsLive)
{
var server = NadekoBot.Client.GetGuild(fs.GuildId);
var channel = server?.GetTextChannel(fs.ChannelId);
if (channel == null)
return;
try { await channel.EmbedAsync(fs.GetEmbed(newStatus).Build()).ConfigureAwait(false); } catch { }
}
}
catch { }
}));
FirstPass = false;
}, null, TimeSpan.Zero, TimeSpan.FromSeconds(60));
@ -190,40 +190,6 @@ namespace NadekoBot.Modules.Searches
return null;
}
//[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)]
//public async Task Test(IUserMessage imsg)
//{
// var channel = (ITextChannel)imsg.Channel;
// await channel.EmbedAsync(new Discord.API.Embed()
// {
// Title = "Imqtpie",
// Url = "https://twitch.tv/masterkwoth",
// Fields = new[] {
// new Discord.API.EmbedField()
// {
// Name = "Status",
// Value = "Online",
// Inline = true,
// },
// new Discord.API.EmbedField()
// {
// Name = "Viewers",
// Value = "123123",
// Inline = true
// },
// new Discord.API.EmbedField()
// {
// Name = "Platform",
// Value = "Twitch",
// Inline = true
// },
// },
// Color = NadekoBot.OkColor
// });
//}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.ManageMessages)]
@ -262,7 +228,7 @@ namespace NadekoBot.Modules.Searches
if (!streams.Any())
{
await channel.SendMessageAsync("You are not following any streams on this server.").ConfigureAwait(false);
await channel.SendConfirmAsync("You are not following any streams on this server.").ConfigureAwait(false);
return;
}
@ -271,7 +237,7 @@ namespace NadekoBot.Modules.Searches
return $"`{snc.Username}`'s stream on **{channel.Guild.GetTextChannel(snc.ChannelId)?.Name}** channel. 【`{snc.Type.ToString()}`】";
}));
await channel.SendMessageAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false);
await channel.SendConfirmAsync($"You are following **{streams.Count()}** streams on this server.\n\n" + text).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -300,10 +266,10 @@ namespace NadekoBot.Modules.Searches
}
if (!removed)
{
await channel.SendMessageAsync("❎ No such stream.").ConfigureAwait(false);
await channel.SendErrorAsync("No such stream.").ConfigureAwait(false);
return;
}
await channel.SendMessageAsync($"🗑 Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false);
await channel.SendConfirmAsync($"Removed `{username}`'s stream ({type}) from notifications.").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -324,22 +290,22 @@ namespace NadekoBot.Modules.Searches
}));
if (streamStatus.IsLive)
{
await channel.SendMessageAsync($"`Streamer {username} is online with {streamStatus.Views} viewers.`");
await channel.SendConfirmAsync($"Streamer {username} is online with {streamStatus.Views} viewers.");
}
else
{
await channel.SendMessageAsync($"`Streamer {username} is offline.`");
await channel.SendConfirmAsync($"Streamer {username} is offline.");
}
}
catch
{
await channel.SendMessageAsync("No channel found.");
await channel.SendErrorAsync("No channel found.");
}
}
private async Task TrackStream(ITextChannel channel, string username, FollowedStream.FollowedStreamType type)
{
username = username.Trim();
username = username.ToLowerInvariant().Trim();
var fs = new FollowedStream
{
GuildId = channel.Guild.Id,
@ -355,7 +321,7 @@ namespace NadekoBot.Modules.Searches
}
catch
{
await channel.SendMessageAsync("💢 Stream probably doesn't exist.").ConfigureAwait(false);
await channel.SendErrorAsync("Stream probably doesn't exist.").ConfigureAwait(false);
return;
}
@ -366,9 +332,7 @@ namespace NadekoBot.Modules.Searches
.Add(fs);
await uow.CompleteAsync().ConfigureAwait(false);
}
var msg = $"🆗 I will notify this channel when status changes.";
await channel.EmbedAsync(fs.GetEmbed(status).Build(), msg).ConfigureAwait(false);
await channel.EmbedAsync(fs.GetEmbed(status).Build(), $"🆗 I will notify this channel when status changes.").ConfigureAwait(false);
}
}
}

View File

@ -75,12 +75,12 @@ namespace NadekoBot.Modules.Searches
{
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
var translation = await TranslateInternal(umsg, langs, text);
await channel.SendMessageAsync(translation).ConfigureAwait(false);
await channel.SendConfirmAsync(translation).ConfigureAwait(false);
}
catch
{
await channel.SendMessageAsync("Bad input format, or something went wrong...").ConfigureAwait(false);
await channel.SendErrorAsync("Bad input format, or something went wrong...").ConfigureAwait(false);
}
}
@ -114,19 +114,19 @@ namespace NadekoBot.Modules.Searches
if (autoDelete == AutoDeleteAutoTranslate.Del)
{
TranslatedChannels.AddOrUpdate(channel.Id, true, (key, val) => true);
try { await channel.SendMessageAsync("`Started automatic translation of messages on this channel. User messages will be auto-deleted.`").ConfigureAwait(false); } catch { }
try { await channel.SendConfirmAsync("Started automatic translation of messages on this channel. User messages will be auto-deleted.").ConfigureAwait(false); } catch { }
return;
}
bool throwaway;
if (TranslatedChannels.TryRemove(channel.Id, out throwaway))
{
try { await channel.SendMessageAsync("`Stopped automatic translation of messages on this channel.`").ConfigureAwait(false); } catch { }
try { await channel.SendConfirmAsync("Stopped automatic translation of messages on this channel.").ConfigureAwait(false); } catch { }
return;
}
else if (TranslatedChannels.TryAdd(channel.Id, autoDelete == AutoDeleteAutoTranslate.Del))
{
try { await channel.SendMessageAsync("`Started automatic translation of messages on this channel.`").ConfigureAwait(false); } catch { }
try { await channel.SendConfirmAsync("Started automatic translation of messages on this channel.").ConfigureAwait(false); } catch { }
}
}
@ -145,7 +145,7 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(langs))
{
if (UserLanguages.TryRemove(ucp, out langs))
await channel.SendMessageAsync($"{msg.Author.Mention}'s auto-translate language has been removed.").ConfigureAwait(false);
await channel.SendConfirmAsync($"{msg.Author.Mention}'s auto-translate language has been removed.").ConfigureAwait(false);
return;
}
@ -157,13 +157,13 @@ namespace NadekoBot.Modules.Searches
if (!GoogleTranslator.Instance.Languages.Contains(from) || !GoogleTranslator.Instance.Languages.Contains(to))
{
try { await channel.SendMessageAsync("`Invalid source and/or target Language.`").ConfigureAwait(false); } catch { }
try { await channel.SendErrorAsync("Invalid source and/or target language.").ConfigureAwait(false); } catch { }
return;
}
UserLanguages.AddOrUpdate(ucp, langs, (key, val) => langs);
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
await channel.SendConfirmAsync($"Your auto-translate language has been set to {from}>{to}").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]

View File

@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using Newtonsoft.Json;
using System.Net.Http;
@ -55,12 +56,17 @@ namespace NadekoBot.Modules.Searches
var res = await http.GetStringAsync($"{xkcdUrl}/{num}/info.0.json").ConfigureAwait(false);
var comic = JsonConvert.DeserializeObject<XkcdComic>(res);
var sent = await channel.SendMessageAsync($"{msg.Author.Mention} " + comic.ToString())
var embed = new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithImage(eib => eib.WithUrl(comic.ImageLink))
.WithAuthor(eab => eab.WithName(comic.Title).WithUrl($"{xkcdUrl}/{num}").WithIconUrl("http://xkcd.com/s/919f27.ico"))
.AddField(efb => efb.WithName("Comic#").WithValue(comic.Num.ToString()).WithIsInline(true))
.AddField(efb => efb.WithName("Date").WithValue($"{comic.Month}/{comic.Year}").WithIsInline(true));
var sent = await channel.EmbedAsync(embed.Build())
.ConfigureAwait(false);
await Task.Delay(10000).ConfigureAwait(false);
await sent.ModifyAsync(m => m.Content = sent.Content + $"\n`Alt:` {comic.Alt}");
await sent.ModifyAsync(m => m.Embed = embed.AddField(efb => efb.WithName("Alt").WithValue(comic.Alt.ToString()).WithIsInline(false)).Build());
}
}
}

View File

@ -199,7 +199,7 @@ namespace NadekoBot.Modules.Searches
if (shortened == arg)
{
await msg.Channel.SendErrorAsync("Failed to shorten that url.");
await msg.Channel.SendErrorAsync("Failed to shorten that url.").ConfigureAwait(false);
}
await msg.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
@ -207,7 +207,8 @@ namespace NadekoBot.Modules.Searches
.WithValue($"<{arg}>"))
.AddField(efb => efb.WithName("Short Url")
.WithValue($"<{shortened}>"))
.Build());
.Build())
.ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -286,7 +287,7 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.MashapeKey))
{
await channel.SendErrorAsync ("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
await channel.SendErrorAsync("Bot owner didn't specify MashapeApiKey. You can't use this functionality.").ConfigureAwait(false);
return;
}

View File

@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Utility
{
public static List<ConvertUnit> Units { get; set; } = new List<ConvertUnit>();
private static Logger _log;
private static Logger _log { get; }
private static Timer _timer;
private static TimeSpan updateInterval = new TimeSpan(12, 0, 0);