Fix to v+t, finished typing articles?

This commit is contained in:
Kwoth
2016-09-01 03:12:08 +02:00
parent fdc6967bd0
commit 6d2c9970a7
57 changed files with 757 additions and 908 deletions

View File

@@ -13,7 +13,7 @@
////todo Add flags for every event
//namespace NadekoBot.Modules.Administration
//{
// internal class LogCommand : DiscordCommand
// public class LogCommand : DiscordCommand
// {
// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
@@ -373,7 +373,7 @@
// catch { }
// }
// internal override void Init(CommandGroupBuilder cgb)
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "spmom")

View File

@@ -23,6 +23,7 @@ namespace NadekoBot.Modules.Administration
public VoicePlusTextCommands()
{
NadekoBot.Client.UserUpdated += UserUpdatedEventHandler;
voicePlusTextCache = new ConcurrentDictionary<ulong, bool>();
}
private Task UserUpdatedEventHandler(IGuildUser before, IGuildUser after)

View File

@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Gambling
private ConcurrentQueue<string> animals { get; }
public bool Fail { get; internal set; }
public bool Fail { get; set; }
public List<Participant> participants = new List<Participant>();
private ulong serverId;

View File

@@ -17,14 +17,14 @@ namespace NadekoBot.Modules.Gambling
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public Task Roll(IUserMessage umsg, [Remainder] string arg = null) =>
InternalRoll(umsg, arg, true);
publicRoll(umsg, arg, true);
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public Task Rolluo(IUserMessage umsg, [Remainder] string arg = null) =>
InternalRoll(umsg, arg, false);
publicRoll(umsg, arg, false);
//todo drawing
private async Task InternalRoll(IUserMessage umsg, string arg, bool ordered)
private async Task publicRoll(IUserMessage umsg, string arg, bool ordered)
{
var channel = (ITextChannel)umsg.Channel;
var r = new Random();

View File

@@ -11,11 +11,11 @@
////todo drawing
//namespace NadekoBot.Modules.Gambling
//{
// internal class DrawCommand : DiscordCommand
// public class DrawCommand : DiscordCommand
// {
// public DrawCommand(DiscordModule module) : base(module) { }
// internal override void Init(CommandGroupBuilder cgb)
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "draw")
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")

View File

@@ -63,7 +63,7 @@
// private SemaphoreSlim locker = new SemaphoreSlim(1,1);
// internal override void Init(CommandGroupBuilder cgb)
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "pick")
// .Description($"Picks a flower planted in this channel. | `{Prefix}pick`")

View File

@@ -1,196 +1,190 @@
//using Discord;
//using Discord.Commands;
//using NadekoBot.Classes;
//using NadekoBot.DataModels;
//using NadekoBot.Extensions;
//using System;
//using System.Collections.Concurrent;
//using System.Collections.Generic;
//using System.Diagnostics;
//using System.Linq;
//using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
////todo DB
////todo Rewrite?
//namespace NadekoBot.Modules.Games
//{
// public static class SentencesProvider
// {
// internal static string GetRandomSentence()
// {
// var data = DbHandler.Instance.GetAllRows<TypingArticle>();
// try
// {
// return data.ToList()[new Random().Next(0, data.Count())].Text;
// }
// catch
// {
// return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`.";
// }
// }
// }
namespace NadekoBot.Modules.Games
{
public class TypingGame
{
public const float WORD_VALUE = 4.5f;
private readonly ITextChannel channel;
public string CurrentSentence;
public bool IsActive;
private readonly Stopwatch sw;
private readonly List<ulong> finishedUserIds;
// public class TypingGame
// {
// public const float WORD_VALUE = 4.5f;
// private readonly Channel channel;
// public string CurrentSentence;
// public bool IsActive;
// private readonly Stopwatch sw;
// private readonly List<ulong> finishedUserIds;
public TypingGame(ITextChannel channel)
{
this.channel = channel;
IsActive = false;
sw = new Stopwatch();
finishedUserIds = new List<ulong>();
}
// public TypingGame(Channel channel)
// {
// this.channel = channel;
// IsActive = false;
// sw = new Stopwatch();
// finishedUserIds = new List<ulong>();
// }
public ITextChannel Channel { get; set; }
// public Channel Channell { get; internal set; }
public async Task<bool> Stop()
{
if (!IsActive) return false;
NadekoBot.Client.MessageReceived -= AnswerReceived;
finishedUserIds.Clear();
IsActive = false;
sw.Stop();
sw.Reset();
await channel.SendMessageAsync("Typing contest stopped").ConfigureAwait(false);
return true;
}
// internal async Task<bool> Stop()
// {
// if (!IsActive) return false;
// NadekoBot.Client.MessageReceived -= AnswerReceived;
// finishedUserIds.Clear();
// IsActive = false;
// sw.Stop();
// sw.Reset();
// await channel.Send("Typing contest stopped").ConfigureAwait(false);
// return true;
// }
// internal async Task Start()
// {
// while (true)
// {
// if (IsActive) return; // can't start running game
// IsActive = true;
// CurrentSentence = SentencesProvider.GetRandomSentence();
// var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
// await channel.SendMessageAsync($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
public async Task Start()
{
while (true)
{
if (IsActive) return; // can't start running game
IsActive = true;
CurrentSentence = GetRandomSentence();
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
await channel.SendMessageAsync($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
// var msg = await channel.SendMessageAsync("Starting new typing contest in **3**...").ConfigureAwait(false);
// await Task.Delay(1000).ConfigureAwait(false);
// await msg.Edit("Starting new typing contest in **2**...").ConfigureAwait(false);
// await Task.Delay(1000).ConfigureAwait(false);
// await msg.Edit("Starting new typing contest in **1**...").ConfigureAwait(false);
// await Task.Delay(1000).ConfigureAwait(false);
// await msg.Edit($":book:**{CurrentSentence.Replace(" ", " \x200B")}**:book:").ConfigureAwait(false);
// sw.Start();
// HandleAnswers();
var msg = await channel.SendMessageAsync("Starting new typing contest in **3**...").ConfigureAwait(false);
await Task.Delay(1000).ConfigureAwait(false);
await msg.ModifyAsync(m => m.Content = "Starting new typing contest in **2**...").ConfigureAwait(false);
await Task.Delay(1000).ConfigureAwait(false);
await msg.ModifyAsync(m => m.Content = "Starting new typing contest in **1**...").ConfigureAwait(false);
await Task.Delay(1000).ConfigureAwait(false);
await msg.ModifyAsync(m => m.Content = $":book:**{CurrentSentence.Replace(" ", " \x200B")}**:book:").ConfigureAwait(false);
sw.Start();
HandleAnswers();
// while (i > 0)
// {
// await Task.Delay(1000).ConfigureAwait(false);
// i--;
// if (!IsActive)
// return;
// }
while (i > 0)
{
await Task.Delay(1000).ConfigureAwait(false);
i--;
if (!IsActive)
return;
}
// await Stop().ConfigureAwait(false);
// }
// }
await Stop().ConfigureAwait(false);
}
}
// private void HandleAnswers()
// {
// NadekoBot.Client.MessageReceived += AnswerReceived;
// }
public string GetRandomSentence()
{
using (var uow = DbHandler.UnitOfWork())
{
return uow.TypingArticles.GetRandom()?.Text ?? "No typing articles found. Use `>typeadd` command to add a new article for typing.";
}
// private async void AnswerReceived(object sender, MessageEventArgs e)
// {
// try
// {
// if (e.Channel == null || e.Channel.Id != channel.Id || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id) return;
}
// var guess = e.Message.RawText;
private void HandleAnswers()
{
NadekoBot.Client.MessageReceived += AnswerReceived;
}
// var distance = CurrentSentence.LevenshteinDistance(guess);
// var decision = Judge(distance, guess.Length);
// if (decision && !finishedUserIds.Contains(umsg.Author.Id))
// {
// finishedUserIds.Add(umsg.Author.Id);
// await channel.Send($"{umsg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
// if (finishedUserIds.Count % 2 == 0)
// {
// await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
// }
// }
// }
// catch { }
// }
private async Task AnswerReceived(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null)
return;
try
{
if (channel== null || channel.Id != channel.Id || msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
// private bool Judge(int errors, int textLength) => errors <= textLength / 25;
var guess = msg.Content;
// }
var distance = CurrentSentence.LevenshteinDistance(guess);
var decision = Judge(distance, guess.Length);
if (decision && !finishedUserIds.Contains(msg.Author.Id))
{
finishedUserIds.Add(msg.Author.Id);
await channel.SendMessageAsync($"{msg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
if (finishedUserIds.Count % 2 == 0)
{
await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
}
}
}
catch { }
}
// internal class SpeedTyping : DiscordCommand
// {
private bool Judge(int errors, int textLength) => errors <= textLength / 25;
// public static ConcurrentDictionary<ulong, TypingGame> RunningContests;
}
// public SpeedTyping(DiscordModule module) : base(module)
// {
// RunningContests = new ConcurrentDictionary<ulong, TypingGame>();
// }
[Group]
public class SpeedTypingCommands
{
// public Func<CommandEventArgs, Task> DoFunc() =>
// async e =>
// {
// var game = RunningContests.GetOrAdd(umsg.Author.Server.Id, id => new TypingGame(e.Channel));
public static ConcurrentDictionary<ulong, TypingGame> RunningContests;
// if (game.IsActive)
// {
// await channel.SendMessageAsync(
// $"Contest already running in " +
// $"{game.Channell.Mention} channel.")
// .ConfigureAwait(false);
// }
// else
// {
// await game.Start().ConfigureAwait(false);
// }
// };
public SpeedTypingCommands()
{
RunningContests = new ConcurrentDictionary<ulong, TypingGame>();
}
// private Func<CommandEventArgs, Task> QuitFunc() =>
// async e =>
// {
// TypingGame game;
// if (RunningContests.TryRemove(umsg.Author.Server.Id, out game))
// {
// await game.Stop().ConfigureAwait(false);
// return;
// }
// await channel.SendMessageAsync("No contest to stop on this channel.").ConfigureAwait(false);
// };
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task TypeStart(IUserMessage msg)
{
var channel = (ITextChannel)msg.Channel;
// internal override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "typestart")
// .Description($"Starts a typing contest. | `{Prefix}typestart`")
// .Do(DoFunc());
var game = RunningContests.GetOrAdd(channel.Guild.Id, id => new TypingGame(channel));
// cgb.CreateCommand(Module.Prefix + "typestop")
// .Description($"Stops a typing contest on the current channel. | `{Prefix}typestop`")
// .Do(QuitFunc());
if (game.IsActive)
{
await channel.SendMessageAsync(
$"Contest already running in " +
$"{game.Channel.Mention} channel.")
.ConfigureAwait(false);
}
else
{
await game.Start().ConfigureAwait(false);
}
}
// cgb.CreateCommand(Module.Prefix + "typeadd")
// .Description($"Adds a new article to the typing contest. Owner only. | `{Prefix}typeadd wordswords`")
// .Parameter("text", ParameterType.Unparsed)
// .Do(async e =>
// {
// if (!NadekoBot.IsOwner(umsg.Author.Id) || string.IsNullOrWhiteSpace(text)) return;
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task TypeStop(IUserMessage imsg)
{
var channel = (ITextChannel)imsg.Channel;
TypingGame game;
if (RunningContests.TryRemove(channel.Guild.Id, out game))
{
await game.Stop().ConfigureAwait(false);
return;
}
await channel.SendMessageAsync("No contest to stop on this channel.").ConfigureAwait(false);
}
// DbHandler.Instance.Connection.Insert(new TypingArticle
// {
// Text = text,
// DateAdded = DateTime.Now
// });
////todo owner only
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
//[RequireContext(ContextType.Guild)]
//public async Task Typeadd(IUserMessage imsg, [Remainder] string text)
//{
// var channel = (ITextChannel)imsg.Channel;
// await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
// });
// }
// }
//}
// using (var uow = DbHandler.UnitOfWork())
// {
// uow.TypingArticles.Add(new Services.Database.Models.TypingArticle
// {
// Author = imsg.Author.Username,
// Text = text
// });
// }
// await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
//}
}
}

View File

@@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Games.Trivia
return list[rand];
}
internal void Reload()
public void Reload()
{
var arr = JArray.Parse(File.ReadAllText("data/triviaquestions.json"));

View File

@@ -234,7 +234,7 @@ namespace NadekoBot.Modules.Music.Classes
});
}
internal void ClearQueue()
public void ClearQueue()
{
actionQueue.Enqueue(() =>
{
@@ -256,7 +256,7 @@ namespace NadekoBot.Modules.Music.Classes
});
}
internal Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
public Task MoveToVoiceChannel(IVoiceChannel voiceChannel)
{
if (audioClient?.ConnectionState != ConnectionState.Connected)
throw new InvalidOperationException("Can't move while bot is not connected to voice channel.");
@@ -264,13 +264,13 @@ namespace NadekoBot.Modules.Music.Classes
return PlaybackVoiceChannel.ConnectAsync();
}
internal bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
public bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong;
internal bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist;
public bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist;
internal bool ToggleAutoplay() => this.Autoplay = !this.Autoplay;
public bool ToggleAutoplay() => this.Autoplay = !this.Autoplay;
internal void ThrowIfQueueFull()
public void ThrowIfQueueFull()
{
if (MaxQueueSize == 0)
return;

View File

@@ -16,18 +16,18 @@ namespace NadekoBot.Modules.Music.Classes
{
public class SongInfo
{
public string Provider { get; internal set; }
public MusicType ProviderType { get; internal set; }
public string Provider { get; set; }
public MusicType ProviderType { get; set; }
/// <summary>
/// Will be set only if the providertype is normal
/// </summary>
public string Query { get; internal set; }
public string Title { get; internal set; }
public string Uri { get; internal set; }
public string Query { get; set; }
public string Title { get; set; }
public string Uri { get; set; }
}
public class Song
{
public StreamState State { get; internal set; }
public StreamState State { get; set; }
public string PrettyName =>
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}` `by {QueuerName}`";
public SongInfo SongInfo { get; }
@@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Music.Classes
return this;
}
internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken)
public async Task Play(IAudioClient voiceClient, CancellationToken cancelToken)
{
var filename = Path.Combine(Music.MusicDataPath, DateTime.Now.UnixTimestamp().ToString());

View File

@@ -40,7 +40,7 @@ namespace NadekoBot.Modules.Music.Classes
public bool IsSoundCloudLink(string url) =>
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
internal async Task<SoundCloudVideo> GetVideoByQueryAsync(string query)
public async Task<SoundCloudVideo> GetVideoByQueryAsync(string query)
{
if (string.IsNullOrWhiteSpace(query))
throw new ArgumentNullException(nameof(query));

View File

@@ -204,7 +204,7 @@ namespace NadekoBot.Modules.NSFW
}
internal static async Task<string> GetE621ImageLink(string tags)
public static async Task<string> GetE621ImageLink(string tags)
{
try
{

View File

@@ -30,7 +30,7 @@
// }
// internal override void Init(CommandGroupBuilder cgb)
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "convert")
// .Description($"Convert quantities from>to. | `{Prefix}convert m>km 1000`")

View File

@@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Searches
// public float StatScore { get; set; }
// }
// internal override void Init(CommandGroupBuilder cgb)
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "lolchamp")
// .Description($"Shows League Of Legends champion statistics. If there are spaces/apostrophes or in the name - omit them. Optional second parameter is a role. |`{Prefix}lolchamp Riven` or `{Prefix}lolchamp Annie sup`")

View File

@@ -11,7 +11,7 @@
////todo rewrite
//namespace NadekoBot.Modules.Trello
//{
// internal class Trello : DiscordModule
// public class Trello : DiscordModule
// {
// private readonly Timer t = new Timer { Interval = 2000 };
// public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Trello;