all nsfw commands except ~hentaibomb and ~autohentai will work on public bot again

This commit is contained in:
Kwoth 2017-02-11 16:26:04 +01:00
parent 4d2d27d48f
commit 12eb216a4b

View File

@ -19,7 +19,7 @@ namespace NadekoBot.Modules.NSFW
[NadekoModule("NSFW", "~")]
public class NSFW : DiscordModule
{
#if !GLOBAL_NADEKO
private static ConcurrentDictionary<ulong, Timer> AutoHentaiTimers { get; } = new ConcurrentDictionary<ulong, Timer>();
private static ConcurrentHashSet<ulong> _hentaiBombBlacklist { get; } = new ConcurrentHashSet<ulong>();
@ -66,79 +66,79 @@ namespace NadekoBot.Modules.NSFW
public Task Hentai([Remainder] string tag = null) =>
InternalHentai(Context.Channel, tag, false);
[NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(ChannelPermission.ManageMessages)]
public async Task AutoHentai(int interval = 0, string tags = null)
{
Timer t;
//[NadekoCommand, Usage, Description, Aliases]
//[RequireUserPermission(ChannelPermission.ManageMessages)]
//public async Task AutoHentai(int interval = 0, string tags = null)
//{
// Timer t;
if (interval == 0)
{
if (AutoHentaiTimers.TryRemove(Context.Channel.Id, out t))
{
t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
await Context.Channel.SendConfirmAsync("Autohentai stopped.").ConfigureAwait(false);
}
return;
}
// if (interval == 0)
// {
// if (AutoHentaiTimers.TryRemove(Context.Channel.Id, out t))
// {
// t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
// await Context.Channel.SendConfirmAsync("Autohentai stopped.").ConfigureAwait(false);
// }
// return;
// }
if (interval < 20)
return;
// if (interval < 20)
// return;
var tagsArr = tags?.Split('|');
// var tagsArr = tags?.Split('|');
t = new Timer(async (state) =>
{
try
{
if (tagsArr == null || tagsArr.Length == 0)
await InternalHentai(Context.Channel, null, true).ConfigureAwait(false);
else
await InternalHentai(Context.Channel, tagsArr[new NadekoRandom().Next(0, tagsArr.Length)], true).ConfigureAwait(false);
}
catch { }
}, null, interval * 1000, interval * 1000);
// t = new Timer(async (state) =>
// {
// try
// {
// if (tagsArr == null || tagsArr.Length == 0)
// await InternalHentai(Context.Channel, null, true).ConfigureAwait(false);
// else
// await InternalHentai(Context.Channel, tagsArr[new NadekoRandom().Next(0, tagsArr.Length)], true).ConfigureAwait(false);
// }
// catch { }
// }, null, interval * 1000, interval * 1000);
AutoHentaiTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) =>
{
old.Change(Timeout.Infinite, Timeout.Infinite);
return t;
});
// AutoHentaiTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) =>
// {
// old.Change(Timeout.Infinite, Timeout.Infinite);
// return t;
// });
await Context.Channel.SendConfirmAsync($"Autohentai started. Reposting every {interval}s with one of the following tags:\n{string.Join(", ", tagsArr)}")
.ConfigureAwait(false);
}
// await Context.Channel.SendConfirmAsync($"Autohentai started. Reposting every {interval}s with one of the following tags:\n{string.Join(", ", tagsArr)}")
// .ConfigureAwait(false);
//}
[NadekoCommand, Usage, Description, Aliases]
public async Task HentaiBomb([Remainder] string tag = null)
{
if (!_hentaiBombBlacklist.Add(Context.User.Id))
return;
try
{
tag = tag?.Trim() ?? "";
tag = "rating%3Aexplicit+" + tag;
//[NadekoCommand, Usage, Description, Aliases]
//public async Task HentaiBomb([Remainder] string tag = null)
//{
// if (!_hentaiBombBlacklist.Add(Context.User.Id))
// return;
// try
// {
// tag = tag?.Trim() ?? "";
// tag = "rating%3Aexplicit+" + tag;
var links = await Task.WhenAll(GetGelbooruImageLink(tag),
GetDanbooruImageLink(tag),
GetKonachanImageLink(tag),
GetYandereImageLink(tag)).ConfigureAwait(false);
// var links = await Task.WhenAll(GetGelbooruImageLink(tag),
// GetDanbooruImageLink(tag),
// GetKonachanImageLink(tag),
// GetYandereImageLink(tag)).ConfigureAwait(false);
var linksEnum = links?.Where(l => l != null);
if (links == null || !linksEnum.Any())
{
await Context.Channel.SendErrorAsync("No results found.").ConfigureAwait(false);
return;
}
// var linksEnum = links?.Where(l => l != null);
// if (links == null || !linksEnum.Any())
// {
// await Context.Channel.SendErrorAsync("No results found.").ConfigureAwait(false);
// return;
// }
await Context.Channel.SendMessageAsync(String.Join("\n\n", linksEnum)).ConfigureAwait(false);
}
finally {
await Task.Delay(5000).ConfigureAwait(false);
_hentaiBombBlacklist.TryRemove(Context.User.Id);
}
}
// await Context.Channel.SendMessageAsync(String.Join("\n\n", linksEnum)).ConfigureAwait(false);
// }
// finally {
// await Task.Delay(5000).ConfigureAwait(false);
// _hentaiBombBlacklist.TryRemove(Context.User.Id);
// }
//}
[NadekoCommand, Usage, Description, Aliases]
public Task Yandere([Remainder] string tag = null)
@ -147,7 +147,7 @@ namespace NadekoBot.Modules.NSFW
[NadekoCommand, Usage, Description, Aliases]
public Task Konachan([Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(Context.Message, tag, Searches.Searches.DapiSearchType.Konachan);
#endif
[NadekoCommand, Usage, Description, Aliases]
public async Task E621([Remainder] string tag = null)
{
@ -279,7 +279,6 @@ namespace NadekoBot.Modules.NSFW
public static Task<string> GetRule34ImageLink(string tag) =>
Searches.Searches.InternalDapiSearch(tag, Searches.Searches.DapiSearchType.Rule34);
#if !GLOBAL_NADEKO
public static Task<string> GetYandereImageLink(string tag) =>
Searches.Searches.InternalDapiSearch(tag, Searches.Searches.DapiSearchType.Yandere);
@ -288,6 +287,5 @@ namespace NadekoBot.Modules.NSFW
public static Task<string> GetGelbooruImageLink(string tag) =>
Searches.Searches.InternalDapiSearch(tag, Searches.Searches.DapiSearchType.Gelbooru);
#endif
}
}