sneakygamestatus event added
This commit is contained in:
parent
81a4d553be
commit
fab46bc3f2
@ -9,6 +9,8 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using NadekoBot.Services.Database;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Gambling
|
namespace NadekoBot.Modules.Gambling
|
||||||
{
|
{
|
||||||
@ -19,15 +21,27 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
public enum CurrencyEvent
|
public enum CurrencyEvent
|
||||||
{
|
{
|
||||||
FlowerReaction
|
FlowerReaction,
|
||||||
|
SneakyGameStatus
|
||||||
}
|
}
|
||||||
//flower reaction event
|
//flower reaction event
|
||||||
public static readonly ConcurrentHashSet<ulong> _flowerReactionAwardedUsers = new ConcurrentHashSet<ulong>();
|
public static readonly ConcurrentHashSet<ulong> _flowerReactionAwardedUsers = new ConcurrentHashSet<ulong>();
|
||||||
|
|
||||||
|
|
||||||
|
private static readonly char[] _sneakyGameStatusChars = Enumerable.Range(48, 10)
|
||||||
|
.Concat(Enumerable.Range(65, 26))
|
||||||
|
.Concat(Enumerable.Range(97, 26))
|
||||||
|
.Select(x => (char)x)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
public static readonly ConcurrentHashSet<ulong> _sneakyGameAwardedUsers = new ConcurrentHashSet<ulong>();
|
||||||
|
|
||||||
|
private static string _secretCode = String.Empty;
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task StartEvent(CurrencyEvent e)
|
public async Task StartEvent(CurrencyEvent e, int arg = -1)
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)Context.Channel;
|
var channel = (ITextChannel)Context.Channel;
|
||||||
try
|
try
|
||||||
@ -38,6 +52,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
case CurrencyEvent.FlowerReaction:
|
case CurrencyEvent.FlowerReaction:
|
||||||
await FlowerReactionEvent(Context).ConfigureAwait(false);
|
await FlowerReactionEvent(Context).ConfigureAwait(false);
|
||||||
break;
|
break;
|
||||||
|
case CurrencyEvent.SneakyGameStatus:
|
||||||
|
await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -45,6 +62,63 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task SneakyGameStatusEvent(CommandContext Context, int? arg)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
if (arg == null || arg < 5)
|
||||||
|
num = 60;
|
||||||
|
else
|
||||||
|
num = arg.Value;
|
||||||
|
|
||||||
|
if (_secretCode != String.Empty)
|
||||||
|
return;
|
||||||
|
var rng = new NadekoRandom();
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
_secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
await NadekoBot.Client.SetGameAsync($"type {_secretCode} for " + NadekoBot.BotConfig.CurrencyPluralName)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Context.Channel.SendConfirmAsync($"SneakyGameStatus event started",
|
||||||
|
$"Users must type a secret code to get 100 currency.\n" +
|
||||||
|
$"Lasts {num} seconds. Don't tell anyone. Shhh.")
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
|
||||||
|
NadekoBot.Client.MessageReceived += SneakyGameMessageReceivedEventHandler;
|
||||||
|
await Task.Delay(num * 1000);
|
||||||
|
NadekoBot.Client.MessageReceived -= SneakyGameMessageReceivedEventHandler;
|
||||||
|
|
||||||
|
_sneakyGameAwardedUsers.Clear();
|
||||||
|
_secretCode = String.Empty;
|
||||||
|
|
||||||
|
await NadekoBot.Client.SetGameAsync($"SneakyGame event ended.")
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task SneakyGameMessageReceivedEventHandler(SocketMessage arg)
|
||||||
|
{
|
||||||
|
if (arg.Content == _secretCode &&
|
||||||
|
_sneakyGameAwardedUsers.Add(arg.Author.Id))
|
||||||
|
{
|
||||||
|
var _ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await CurrencyHandler.AddCurrencyAsync(arg.Author, "Sneaky Game Event", 100, false)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
try { await arg.DeleteAsync(new RequestOptions() { RetryMode = RetryMode.AlwaysFail }).ConfigureAwait(false); }
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.Delay(0);
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task FlowerReactionEvent(CommandContext Context)
|
public static async Task FlowerReactionEvent(CommandContext Context)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user