more speedtyping.
This commit is contained in:
parent
9284b191ca
commit
2851a763f6
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
|
||||
namespace NadekoBot.Classes {
|
||||
|
||||
public static class SentencesProvider {
|
||||
|
||||
}
|
||||
|
||||
public class TypingGame {
|
||||
private Channel channel;
|
||||
|
||||
public TypingGame(Channel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public Channel Channell { get; internal set; }
|
||||
|
||||
internal bool Stop() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void Start() {
|
||||
}
|
||||
}
|
||||
|
||||
class SpeedTyping : DiscordCommand {
|
||||
|
||||
private static Dictionary<ulong, TypingGame> runningContests;
|
||||
|
||||
public SpeedTyping() : base() {
|
||||
runningContests = new Dictionary<ulong, TypingGame>();
|
||||
}
|
||||
|
||||
public override Func<CommandEventArgs, Task> DoFunc()=>
|
||||
async e => {
|
||||
if (runningContests.ContainsKey(e.User.Server.Id)) {
|
||||
await e.Send($"Contest already running in { runningContests[e.User.Server.Id].Channell.Mention } channel.");
|
||||
return;
|
||||
}
|
||||
var tg = new TypingGame(e.Channel);
|
||||
runningContests.Add(e.Server.Id,tg);
|
||||
await e.Send("Starting new typing contest!");
|
||||
tg.Start();
|
||||
};
|
||||
|
||||
private Func<CommandEventArgs,Task> QuitFunc() =>
|
||||
async e => {
|
||||
if (runningContests.ContainsKey(e.User.Server.Id) &&
|
||||
runningContests[e.User.Server.Id].Stop())
|
||||
{
|
||||
runningContests.Remove(e.User.Server.Id);
|
||||
await e.Send("Typing contest stopped");
|
||||
return;
|
||||
}
|
||||
await e.Send("No contest to stop on this channel.");
|
||||
};
|
||||
|
||||
public override void Init(CommandGroupBuilder cgb) {
|
||||
/*
|
||||
cgb.CreateCommand("typing start")
|
||||
.Description("Starts a typing contest.")
|
||||
.Do(DoFunc());
|
||||
|
||||
cgb.CreateCommand("typing stop")
|
||||
.Description("Stops a typing contest on the current channel.")
|
||||
.Do(QuitFunc());
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
123
NadekoBot/Commands/SpeedTyping.cs
Normal file
123
NadekoBot/Commands/SpeedTyping.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Threading;
|
||||
|
||||
namespace NadekoBot {
|
||||
|
||||
public static class SentencesProvider {
|
||||
internal static string GetRandomSentence() {
|
||||
return "Random test sentence.";
|
||||
}
|
||||
}
|
||||
|
||||
public class TypingGame {
|
||||
private Channel channel;
|
||||
public string currentSentence;
|
||||
public bool IsActive;
|
||||
|
||||
public TypingGame(Channel channel) {
|
||||
this.channel = channel;
|
||||
currentSentence = SentencesProvider.GetRandomSentence();
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
public Channel Channell { get; internal set; }
|
||||
|
||||
internal async Task<bool> Stop() {
|
||||
if (!IsActive) return false;
|
||||
IsActive = false;
|
||||
NadekoBot.client.MessageReceived -= AnswerReceived;
|
||||
await channel.Send("Typing contest stopped");
|
||||
return true;
|
||||
}
|
||||
|
||||
internal async Task Start() {
|
||||
IsActive = true;
|
||||
var msg = await channel.SendMessage("Starting new typing contest in **3**....");
|
||||
await Task.Delay(1000);
|
||||
await msg.Edit("Starting new typing contest in **2**....");
|
||||
await Task.Delay(1000);
|
||||
await msg.Edit("Starting new typing contest in **1**....");
|
||||
await Task.Delay(1000);
|
||||
await msg.Edit($"**{currentSentence}**");
|
||||
|
||||
HandleAnswers();
|
||||
int i = 10;
|
||||
while (i > 0) {
|
||||
await Task.Delay(1000);
|
||||
i--;
|
||||
if (!IsActive)
|
||||
break;
|
||||
}
|
||||
|
||||
await Stop();
|
||||
}
|
||||
|
||||
private void HandleAnswers() {
|
||||
NadekoBot.client.MessageReceived += AnswerReceived;
|
||||
}
|
||||
|
||||
private async void AnswerReceived(object sender, MessageEventArgs e) {
|
||||
if (e.Channel == null || e.Channel.Id != channel.Id) return;
|
||||
|
||||
var guess = e.Message.RawText;
|
||||
|
||||
if (currentSentence == guess) {
|
||||
await channel.Send(e.User.Mention + " finished!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SpeedTyping : DiscordCommand {
|
||||
|
||||
private static Dictionary<ulong, TypingGame> runningContests;
|
||||
|
||||
public SpeedTyping() : base() {
|
||||
runningContests = new Dictionary<ulong, TypingGame>();
|
||||
}
|
||||
|
||||
public override Func<CommandEventArgs, Task> DoFunc()=>
|
||||
async e => {
|
||||
if (runningContests.ContainsKey(e.User.Server.Id) && runningContests[e.User.Server.Id].IsActive) {
|
||||
await e.Send($"Contest already running in { runningContests[e.User.Server.Id].Channell.Mention } channel.");
|
||||
return;
|
||||
}
|
||||
if (runningContests.ContainsKey(e.User.Server.Id) && !runningContests[e.User.Server.Id].IsActive) {
|
||||
await runningContests[e.User.Server.Id].Start();
|
||||
return;
|
||||
}
|
||||
var tg = new TypingGame(e.Channel);
|
||||
runningContests.Add(e.Server.Id,tg);
|
||||
await tg.Start();
|
||||
};
|
||||
|
||||
private Func<CommandEventArgs,Task> QuitFunc() =>
|
||||
async e => {
|
||||
if (runningContests.ContainsKey(e.User.Server.Id) &&
|
||||
await runningContests[e.User.Server.Id].Stop())
|
||||
{
|
||||
runningContests.Remove(e.User.Server.Id);
|
||||
return;
|
||||
}
|
||||
await e.Send("No contest to stop on this channel.");
|
||||
};
|
||||
|
||||
public override void Init(CommandGroupBuilder cgb) {
|
||||
/*
|
||||
cgb.CreateCommand("typestart")
|
||||
.Description("Starts a typing contest.")
|
||||
.Do(DoFunc());
|
||||
|
||||
cgb.CreateCommand("typestop")
|
||||
.Description("Stops a typing contest on the current channel.")
|
||||
.Do(QuitFunc());
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace NadekoBot.Modules
|
||||
{
|
||||
public Games() : base() {
|
||||
commands.Add(new Trivia());
|
||||
//commands.Add(new SpeedTyping());
|
||||
commands.Add(new SpeedTyping());
|
||||
}
|
||||
|
||||
public override void Install(ModuleManager manager)
|
||||
|
@ -141,7 +141,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Classes\SParser.cs" />
|
||||
<Compile Include="Classes\SpeedTyping.cs" />
|
||||
<Compile Include="Commands\SpeedTyping.cs" />
|
||||
<Compile Include="Classes\_JSONModels.cs" />
|
||||
<Compile Include="Classes\Cards.cs" />
|
||||
<Compile Include="Classes\Extensions.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user