2016-12-17 00:16:14 +00:00
|
|
|
|
using Discord.Commands;
|
2016-12-14 23:56:13 +00:00
|
|
|
|
using NadekoBot.Attributes;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-02-18 20:07:36 +00:00
|
|
|
|
using NadekoBot.Modules.Games.Hangman;
|
2017-02-21 17:46:17 +00:00
|
|
|
|
using Discord;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using Discord.WebSocket;
|
2016-12-14 23:56:13 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Games
|
|
|
|
|
{
|
|
|
|
|
public partial class Games
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-02-19 14:18:40 +00:00
|
|
|
|
public class HangmanCommands : NadekoSubmodule
|
2016-12-14 23:56:13 +00:00
|
|
|
|
{
|
2017-06-19 13:42:10 +00:00
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
|
2017-06-19 13:42:10 +00:00
|
|
|
|
public HangmanCommands(DiscordSocketClient client)
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
_client = client;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 23:56:13 +00:00
|
|
|
|
//channelId, game
|
|
|
|
|
public static ConcurrentDictionary<ulong, HangmanGame> HangmanGames { get; } = new ConcurrentDictionary<ulong, HangmanGame>();
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2017-06-28 01:42:02 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Hangmanlist()
|
2016-12-14 23:56:13 +00:00
|
|
|
|
{
|
2017-02-23 22:30:38 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(Format.Code(GetText("hangman_types", Prefix)) + "\n" + string.Join(", ", HangmanTermPool.data.Keys));
|
2016-12-14 23:56:13 +00:00
|
|
|
|
}
|
2017-01-08 07:57:26 +00:00
|
|
|
|
|
2016-12-14 23:56:13 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2017-06-28 01:42:02 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-08 08:48:35 +00:00
|
|
|
|
public async Task Hangman([Remainder]string type = "All")
|
2016-12-14 23:56:13 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
var hm = new HangmanGame(_client, Context.Channel, type);
|
2016-12-14 23:56:13 +00:00
|
|
|
|
|
2016-12-16 18:43:57 +00:00
|
|
|
|
if (!HangmanGames.TryAdd(Context.Channel.Id, hm))
|
2016-12-14 23:56:13 +00:00
|
|
|
|
{
|
2017-02-21 17:46:17 +00:00
|
|
|
|
await ReplyErrorLocalized("hangman_running").ConfigureAwait(false);
|
2016-12-14 23:56:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
hm.OnEnded += g =>
|
2016-12-14 23:56:13 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
HangmanGames.TryRemove(g.GameChannel.Id, out HangmanGame throwaway);
|
2016-12-14 23:56:13 +00:00
|
|
|
|
};
|
2017-01-08 08:48:35 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
hm.Start();
|
|
|
|
|
}
|
2017-01-11 12:54:25 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-02-21 17:46:17 +00:00
|
|
|
|
try { await Context.Channel.SendErrorAsync(GetText("hangman_start_errored") + " " + ex.Message).ConfigureAwait(false); } catch { }
|
2017-05-27 08:19:27 +00:00
|
|
|
|
HangmanGames.TryRemove(Context.Channel.Id, out HangmanGame throwaway);
|
2017-01-11 12:54:25 +00:00
|
|
|
|
throwaway.Dispose();
|
2017-01-08 08:48:35 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-14 23:56:13 +00:00
|
|
|
|
|
2017-02-21 17:46:17 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(GetText("hangman_game_started"), hm.ScrambledWord + "\n" + hm.GetHangman());
|
2016-12-14 23:56:13 +00:00
|
|
|
|
}
|
2017-06-28 01:42:02 +00:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task HangmanStop()
|
|
|
|
|
{
|
|
|
|
|
if (HangmanGames.TryRemove(Context.Channel.Id, out HangmanGame throwaway))
|
|
|
|
|
{
|
|
|
|
|
throwaway.Dispose();
|
|
|
|
|
await ReplyConfirmLocalized("hangman_stopped").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-14 23:56:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|