From acebc6e9149a02bb552452fd174c0c3434fb433e Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 20 Aug 2016 17:02:33 +0200 Subject: [PATCH] Animal racing done, more mass replacements --- src/NadekoBot/Classes/FlowersHandler.cs | 4 +- .../Administration/AdministrationModule.cs | 4 +- .../Commands/CrossServerTextChannel.cs | 4 +- .../Commands/IncidentsCommands.cs | 2 +- .../Administration/Commands/LogCommand.cs | 38 +- .../Commands/MessageRepeater.cs | 2 +- .../Commands/ServerGreetCommand.cs | 8 +- .../Commands/VoicePlusTextCommand.cs | 2 +- .../Modules/Gambling/Commands/AnimalRacing.cs | 488 +++++++++--------- .../Games/Commands/SpeedTypingCommands.cs | 4 +- .../Commands/StreamNotificationCommands.cs | 2 +- .../Modules/Utility/Commands/Remind.cs | 2 +- src/NadekoBot/_Modules/Music/MusicModule.cs | 12 +- .../Commands/FilterInvitesCommand.cs | 2 +- .../Commands/FilterWordsCommand.cs | 2 +- 15 files changed, 287 insertions(+), 289 deletions(-) diff --git a/src/NadekoBot/Classes/FlowersHandler.cs b/src/NadekoBot/Classes/FlowersHandler.cs index 57191c63..46463c2f 100644 --- a/src/NadekoBot/Classes/FlowersHandler.cs +++ b/src/NadekoBot/Classes/FlowersHandler.cs @@ -23,7 +23,7 @@ namespace NadekoBot.Classes var flows = amount + " " + NadekoBot.Config.CurrencySign; - await u.SendMessage("๐Ÿ‘‘Congratulations!๐Ÿ‘‘\nYou received: " + flows).ConfigureAwait(false); + await u.SendMessageAsync("๐Ÿ‘‘Congratulations!๐Ÿ‘‘\nYou received: " + flows).ConfigureAwait(false); } public static async Task RemoveFlowers(Discord.User u, string reason, int amount, bool silent=false, string message="๐Ÿ‘Ž`Bot owner has taken {0}{1} from you.`") @@ -46,7 +46,7 @@ namespace NadekoBot.Classes if (silent) return true; - await u.SendMessage(string.Format(message,amount,NadekoBot.Config.CurrencySign)).ConfigureAwait(false); + await u.SendMessageAsync(string.Format(message,amount,NadekoBot.Config.CurrencySign)).ConfigureAwait(false); return true; } } diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index 2108bb69..4a8ed546 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -543,7 +543,7 @@ namespace NadekoBot.Modules.Administration // { // return; // } - // await channel.SendMessage(msg); + // await channel.SendMessageAsync(msg); // } // else if (ids[1].ToUpperInvariant().StartsWith("U:")) // { @@ -553,7 +553,7 @@ namespace NadekoBot.Modules.Administration // { // return; // } - // await user.SendMessage(msg); + // await user.SendMessageAsync(msg); // } // else // { diff --git a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs index 3b245324..c08683d6 100644 --- a/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs +++ b/src/NadekoBot/Modules/Administration/Commands/CrossServerTextChannel.cs @@ -26,7 +26,7 @@ // continue; // foreach (var chan in set.Except(new[] { e.Channel })) // { -// await chan.SendMessage(GetText(e.Server, e.Channel, imsg.Author, e.Message)).ConfigureAwait(false); +// await chan.SendMessageAsync(GetText(e.Server, e.Channel, imsg.Author, e.Message)).ConfigureAwait(false); // } // } // } @@ -75,7 +75,7 @@ // if (Subscribers.TryAdd(token, set)) // { // set.Add(e.Channel); -// await imsg.Author.SendMessage("This is your CSC token:" + token.ToString()).ConfigureAwait(false); +// await imsg.Author.SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false); // } // }); diff --git a/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs b/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs index 6722a384..9fa17495 100644 --- a/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/IncidentsCommands.cs @@ -23,7 +23,7 @@ // var incs = DbHandler.Instance.FindAll(i => i.ServerId == sid && i.Read == false); // DbHandler.Instance.Connection.UpdateAll(incs.Select(i => { i.Read = true; return i; })); -// await imsg.Author.SendMessage(string.Join("\n----------------------", incs.Select(i => i.Text))); +// await imsg.Author.SendMessageAsync(string.Join("\n----------------------", incs.Select(i => i.Text))); // }); // cgb.CreateCommand(Module.Prefix + "listallincidents") diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 14524a4f..29da6a02 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -45,7 +45,7 @@ // if (usr?.Status != UserStatus.Offline) // return; // await channel.SendMessageAsync($"User `{usr.Name}` is offline. PM sent.").ConfigureAwait(false); -// await usr.SendMessage( +// await usr.SendMessageAsync( // $"User `{imsg.Author.Username}` mentioned you on " + // $"`{e.Server.Name}` server while you were offline.\n" + // $"`Message:` {e.Message.Text}").ConfigureAwait(false); @@ -76,7 +76,7 @@ // //send merged messages to each channel // foreach (var k in toSend) // { -// try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { } +// try { await k.Key.SendMessageAsync(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { } // } // await Task.Delay(5000); @@ -96,10 +96,10 @@ // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; // if (e.Before.Name != e.After.Name) -// await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*) +// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*) // `New:` {e.After.Name}").ConfigureAwait(false); // else if (e.Before.Topic != e.After.Topic) -// await ch.SendMessage($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*) +// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*) // `Old:` {e.Before.Topic} // `New:` {e.After.Topic}").ConfigureAwait(false); // } @@ -117,7 +117,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"โ—`{prettyCurrentTime}`โ—`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false); +// await ch.SendMessageAsync($"โ—`{prettyCurrentTime}`โ—`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false); // } // catch { } // } @@ -133,7 +133,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"`{prettyCurrentTime}`๐Ÿ†•`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false); +// await ch.SendMessageAsync($"`{prettyCurrentTime}`๐Ÿ†•`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false); // } // catch { } // } @@ -148,7 +148,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"`{prettyCurrentTime}`โ™ป`User was unbanned:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); +// await ch.SendMessageAsync($"`{prettyCurrentTime}`โ™ป`User was unbanned:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); // } // catch { } // } @@ -163,7 +163,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"`{prettyCurrentTime}`โœ…`User joined:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); +// await ch.SendMessageAsync($"`{prettyCurrentTime}`โœ…`User joined:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); // } // catch { } // } @@ -178,7 +178,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"`{prettyCurrentTime}`โ—`User left:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); +// await ch.SendMessageAsync($"`{prettyCurrentTime}`โ—`User left:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); // } // catch { } // } @@ -193,7 +193,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage($"โ—`{prettyCurrentTime}`โŒ`User banned:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); +// await ch.SendMessageAsync($"โ—`{prettyCurrentTime}`โŒ`User banned:` **{imsg.Author.Username}** ({imsg.Author.Id})").ConfigureAwait(false); // } // catch { } // } @@ -213,13 +213,13 @@ // return; // if (!string.IsNullOrWhiteSpace(e.Message.Text)) // { -// await ch.SendMessage( +// await ch.SendMessageAsync( // $@"๐Ÿ•”`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}` //๐Ÿ‘ค`{imsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); // } // else // { -// await ch.SendMessage( +// await ch.SendMessageAsync( // $@"๐Ÿ•”`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}` //๐Ÿ‘ค`{imsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); // } @@ -242,13 +242,13 @@ // return; // if (!string.IsNullOrWhiteSpace(e.Message.Text)) // { -// await ch.SendMessage( +// await ch.SendMessageAsync( // $@"๐Ÿ•”`{prettyCurrentTime}` **Message** ๐Ÿšฎ `#{e.Channel.Name}` //๐Ÿ‘ค`{imsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false); // } // else // { -// await ch.SendMessage( +// await ch.SendMessageAsync( // $@"๐Ÿ•”`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}` //๐Ÿ‘ค`{imsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false); // } @@ -268,7 +268,7 @@ // Channel ch; // if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) // return; -// await ch.SendMessage( +// await ch.SendMessageAsync( // $@"๐Ÿ•”`{prettyCurrentTime}` **Message** ๐Ÿ“ `#{e.Channel.Name}` //๐Ÿ‘ค`{imsg.Author?.ToString() ?? ("NULL")}` // `Old:` {e.Before.Text.Unmention()} @@ -318,15 +318,15 @@ // } // if ((notifyLeave && notifyJoin) && (notifyChAfter == notifyChBefore)) // { -// await notifyChAfter.SendMessage($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false); +// await notifyChAfter.SendMessageAsync($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false); // } // else if (notifyJoin) // { -// await notifyChAfter.SendMessage($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false); +// await notifyChAfter.SendMessageAsync($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false); // } // else if (notifyLeave) // { -// await notifyChBefore.SendMessage($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false); +// await notifyChBefore.SendMessageAsync($"๐ŸŽผ`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false); // } // } // } @@ -368,7 +368,7 @@ // } // else // return; -// await ch.SendMessage(str).ConfigureAwait(false); +// await ch.SendMessageAsync(str).ConfigureAwait(false); // } // catch { } // } diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index f85700f4..4101cf53 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -47,7 +47,7 @@ // catch { } // try // { -// lastMessage = await ch.SendMessage(msg).ConfigureAwait(false); +// lastMessage = await ch.SendMessageAsync(msg).ConfigureAwait(false); // } // catch { } // } diff --git a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs index acdb5964..d8a08c86 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ServerGreetCommand.cs @@ -48,7 +48,7 @@ // Greeted++; // try // { -// await imsg.Author.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg).ConfigureAwait(false); +// await imsg.Author.SendMessageAsync($"`Farewell Message From {e.Server?.Name}`\n" + msg).ConfigureAwait(false); // } // catch { } @@ -57,7 +57,7 @@ // { // if (channel == null) return; // Greeted++; -// var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); +// var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false); // if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) // { // await Task.Delay(30000).ConfigureAwait(false); // 5 minutes @@ -84,13 +84,13 @@ // if (controls.GreetPM) // { // Greeted++; -// await imsg.Author.SendMessage($"`Welcome Message From {e.Server.Name}`\n" + msg).ConfigureAwait(false); +// await imsg.Author.SendMessageAsync($"`Welcome Message From {e.Server.Name}`\n" + msg).ConfigureAwait(false); // } // else // { // if (channel == null) return; // Greeted++; -// var toDelete = await channel.SendMessage(msg).ConfigureAwait(false); +// var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false); // if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages && controls.DeleteGreetMessages) // { // await Task.Delay(30000).ConfigureAwait(false); // 5 minutes diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs index 7643791f..e1671395 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommand.cs @@ -37,7 +37,7 @@ // try // { -// await e.Server.Owner.SendMessage( +// await e.Server.Owner.SendMessageAsync( // "I don't have manage server and/or Manage Channels permission," + // $" so I cannot run voice+text on **{e.Server.Name}** server.").ConfigureAwait(false); // } diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 5a12b643..83a4882e 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -1,5 +1,6 @@ ๏ปฟusing Discord; using Discord.Commands; +using NadekoBot.Attributes; using NadekoBot.Classes; using NadekoBot.Extensions; using System; @@ -11,286 +12,283 @@ using System.Threading.Tasks; namespace NadekoBot.Modules.Gambling.Commands { - [Group] - class AnimalRacing + public partial class Gambling { - public static ConcurrentDictionary AnimalRaces = new ConcurrentDictionary(); - - public AnimalRacing(DiscordModule module) : base(module) + [Group] + public class AnimalRacing { - } + public static ConcurrentDictionary AnimalRaces = new ConcurrentDictionary(); - internal override void Init(CommandGroupBuilder cgb) - { - cgb.CreateCommand(Prefix + "race") - .Description($"Starts a new animal race. | `{Prefix}race`") - .Do(e => - { - var ar = new AnimalRace(e.Server.Id, e.Channel); - if (ar.Fail) - { - return; - } - }); - - - cgb.CreateCommand(Prefix + "joinrace") - .Alias(Prefix + "jr") - .Description($"Joins a new race. You can specify an amount of flowers for betting (optional). You will get YourBet*(participants-1) back if you win. | `{Prefix}jr` or `{Prefix}jr 5`") - .Parameter("amount", ParameterType.Optional) - .Do(async e => - { - - int amount; - if (!int.TryParse(e.GetArg("amount"), out amount) || amount < 0) - amount = 0; - - var userFlowers = Gambling.GetUserFlowers(imsg.Author.Id); - - if (userFlowers < amount) - { - await channel.SendMessageAsync($"{imsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false); - return; - } - - if (amount > 0) - await FlowersHandler.RemoveFlowers(imsg.Author, "BetRace", (int)amount, true).ConfigureAwait(false); - - AnimalRace ar; - if (!AnimalRaces.TryGetValue(e.Server.Id, out ar)) - { - await channel.SendMessageAsync("No race exists on this server"); - return; - } - await ar.JoinRace(imsg.Author, amount); - - }); - } - - public class AnimalRace - { - - private ConcurrentQueue animals = new ConcurrentQueue(NadekoBot.Config.RaceAnimals.Shuffle()); - - public bool Fail { get; internal set; } - - public List participants = new List(); - private ulong serverId; - private int messagesSinceGameStarted = 0; - - public IGuildChannel raceChannel { get; set; } - public bool Started { get; private set; } = false; - - public AnimalRace(ulong serverId, Channel ch) + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + public async Task Race(IMessage imsg) { - this.serverId = serverId; - this.raceChannel = ch; - if (!AnimalRaces.TryAdd(serverId, this)) + var channel = imsg.Channel as ITextChannel; + + var ar = new AnimalRace(channel.Guild.Id, channel); + + if (ar.Fail) + await channel.SendMessageAsync("๐Ÿ `Failed starting a race. Another race is probably running.`"); + } + + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + public async Task JoinRace(IMessage imsg, int amount = 0) + { + var channel = imsg.Channel as ITextChannel; + + if (amount < 0) + amount = 0; + + //todo DB + //var userFlowers = Gambling.GetUserFlowers(imsg.Author.Id); + + //if (userFlowers < amount) + //{ + // await channel.SendMessageAsync($"{imsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false); + // return; + //} + + //if (amount > 0) + // await FlowersHandler.RemoveFlowers(imsg.Author, "BetRace", (int)amount, true).ConfigureAwait(false); + + AnimalRace ar; + if (!AnimalRaces.TryGetValue(channel.Guild.Id, out ar)) { - Fail = true; + await channel.SendMessageAsync("No race exists on this server"); return; } - var cancelSource = new CancellationTokenSource(); - var token = cancelSource.Token; - var fullgame = CheckForFullGameAsync(token); - Task.Run(async () => + await ar.JoinRace(imsg.Author as IGuildUser, amount); + } + + public class AnimalRace + { + + private ConcurrentQueue animals = new ConcurrentQueue(NadekoBot.Config.RaceAnimals.Shuffle()); + + public bool Fail { get; internal set; } + + public List participants = new List(); + private ulong serverId; + private int messagesSinceGameStarted = 0; + + public ITextChannel raceChannel { get; set; } + public bool Started { get; private set; } = false; + + public AnimalRace(ulong serverId, ITextChannel ch) { + this.serverId = serverId; + this.raceChannel = ch; + if (!AnimalRaces.TryAdd(serverId, this)) + { + Fail = true; + return; + } + var cancelSource = new CancellationTokenSource(); + var token = cancelSource.Token; + var fullgame = CheckForFullGameAsync(token); + Task.Run(async () => + { + try + { + //todo Commmand prefixes from config + await raceChannel.SendMessageAsync($"๐Ÿ`Race is starting in 20 seconds or when the room is full. Type $jr to join the race.`"); + var t = await Task.WhenAny(Task.Delay(20000, token), fullgame); + Started = true; + cancelSource.Cancel(); + if (t == fullgame) + { + await raceChannel.SendMessageAsync("๐Ÿ`Race full, starting right now!`"); + } + else if (participants.Count > 1) + { + await raceChannel.SendMessageAsync("๐Ÿ`Game starting with " + participants.Count + " participants.`"); + } + else + { + await raceChannel.SendMessageAsync("๐Ÿ`Race failed to start since there was not enough participants.`"); + var p = participants.FirstOrDefault(); + //todo DB + //if (p != null) + // await FlowersHandler.AddFlowersAsync(p.User, "BetRace", p.AmountBet, true).ConfigureAwait(false); + End(); + return; + } + await Task.Run(StartRace); + End(); + } + catch { } + }); + } + + private void End() + { + AnimalRace throwaway; + AnimalRaces.TryRemove(serverId, out throwaway); + } + + private async Task StartRace() + { + var rng = new Random(); + Participant winner = null; + IMessage msg = null; + int place = 1; try { - await raceChannel.SendMessage($"๐Ÿ`Race is starting in 20 seconds or when the room is full. Type {NadekoBot.Config.CommandPrefixes.Gambling}jr to join the race.`"); - var t = await Task.WhenAny(Task.Delay(20000, token), fullgame); - Started = true; - cancelSource.Cancel(); - if (t == fullgame) - { - await raceChannel.SendMessage("๐Ÿ`Race full, starting right now!`"); - } - else if (participants.Count > 1) - { - await raceChannel.SendMessage("๐Ÿ`Game starting with " + participants.Count + " participants.`"); - } - else - { - await raceChannel.SendMessage("๐Ÿ`Race failed to start since there was not enough participants.`"); - var p = participants.FirstOrDefault(); - if (p != null) - await FlowersHandler.AddFlowersAsync(p.User, "BetRace", p.AmountBet, true).ConfigureAwait(false); - End(); - return; - } - await Task.Run(StartRace); - End(); - } - catch { } - }); - } + NadekoBot.Client.MessageReceived += Client_MessageReceived; - private void End() - { - AnimalRace throwaway; - AnimalRaces.TryRemove(serverId, out throwaway); - } - - private async Task StartRace() - { - var rng = new Random(); - Participant winner = null; - IMessage msg = null; - int place = 1; - try - { - NadekoBot.Client.MessageReceived += Client_MessageReceived; - - while (!participants.All(p => p.Total >= 60)) - { - //update the state - participants.ForEach(p => + while (!participants.All(p => p.Total >= 60)) { - - p.Total += 1 + rng.Next(0, 10); - if (p.Total > 60) + //update the state + participants.ForEach(p => { - p.Total = 60; - if (winner == null) + + p.Total += 1 + rng.Next(0, 10); + if (p.Total > 60) { - winner = p; + p.Total = 60; + if (winner == null) + { + winner = p; + } + if (p.Place == 0) + p.Place = place++; } - if (p.Place == 0) - p.Place = place++; - } - }); + }); - //draw the state + //draw the state - var text = $@"|๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ”š| + var text = $@"|๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ”š| {String.Join("\n", participants.Select(p => $"{(int)(p.Total / 60f * 100),-2}%|{p.ToString()}"))} |๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ๐Ÿ”š|"; - if (msg == null || messagesSinceGameStarted >= 10) // also resend the message if channel was spammed - { - if (msg != null) - try { await msg.Delete(); } catch { } - msg = await raceChannel.SendMessage(text); - messagesSinceGameStarted = 0; - } - else - await msg.Edit(text); + if (msg == null || messagesSinceGameStarted >= 10) // also resend the message if channel was spammed + { + if (msg != null) + try { await msg.DeleteAsync(); } catch { } + msg = await raceChannel.SendMessageAsync(text).ConfigureAwait(false); + messagesSinceGameStarted = 0; + } + else + await msg.ModifyAsync(m => m.Content = text).ConfigureAwait(false); - await Task.Delay(2500); + await Task.Delay(2500); + } + } + finally + { + NadekoBot.Client.MessageReceived -= Client_MessageReceived; + } + + if (winner.AmountBet > 0) + { + var wonAmount = winner.AmountBet * (participants.Count - 1); + //todo DB + //await FlowersHandler.AddFlowersAsync(winner.User, "Won a Race", wonAmount).ConfigureAwait(false); + await raceChannel.SendMessageAsync($"๐Ÿ {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{NadekoBot.Config.Currency.Sign}!**").ConfigureAwait(false); + } + else + { + await raceChannel.SendMessageAsync($"๐Ÿ {winner.User.Mention} as {winner.Animal} **Won the race!**"); + } + + } + + private async Task Client_MessageReceived(IMessage imsg) + { + if (await imsg.IsAuthor(NadekoBot.Client) || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel) + return; + messagesSinceGameStarted++; + } + + private async Task CheckForFullGameAsync(CancellationToken cancelToken) + { + while (animals.Count > 0) + { + await Task.Delay(100, cancelToken); } } - finally - { - NadekoBot.Client.MessageReceived -= Client_MessageReceived; - } - if (winner.AmountBet > 0) + public async Task JoinRace(IGuildUser u, int amount = 0) { - var wonAmount = winner.AmountBet * (participants.Count - 1); - await FlowersHandler.AddFlowersAsync(winner.User, "Won a Race", wonAmount).ConfigureAwait(false); - await raceChannel.SendMessage($"๐Ÿ {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{NadekoBot.Config.CurrencySign}!**"); - } - else - { - await raceChannel.SendMessage($"๐Ÿ {winner.User.Mention} as {winner.Animal} **Won the race!**"); - } - - } - - private void Client_MessageReceived(IMessage imsg) - { - if (e.Message.IsAuthor || e.Channel.IsPrivate || e.Channel != raceChannel) - return; - messagesSinceGameStarted++; - } - - private async Task CheckForFullGameAsync(CancellationToken cancelToken) - { - while (animals.Count > 0) - { - await Task.Delay(100, cancelToken); + var animal = ""; + if (!animals.TryDequeue(out animal)) + { + await raceChannel.SendMessageAsync($"{u.Mention} `There is no running race on this server.`"); + return false; + } + var p = new Participant(u, animal, amount); + if (participants.Contains(p)) + { + await raceChannel.SendMessageAsync($"{u.Mention} `You already joined this race.`"); + return false; + } + if (Started) + { + await raceChannel.SendMessageAsync($"{u.Mention} `Race is already started`"); + return false; + } + participants.Add(p); + await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {(amount == 1? NadekoBot.Config.Currency.Name: NadekoBot.Config.Currency.PluralName)}!**" : "**")); + return true; } } - public async Task JoinRace(IGuildUser u, int amount = 0) + public class Participant { - var animal = ""; - if (!animals.TryDequeue(out animal)) - { - await raceChannel.SendMessage($"{u.Mention} `There is no running race on this server.`"); - return false; - } - var p = new Participant(u, animal, amount); - if (participants.Contains(p)) - { - await raceChannel.SendMessage($"{u.Mention} `You already joined this race.`"); - return false; - } - if (Started) - { - await raceChannel.SendMessage($"{u.Mention} `Race is already started`"); - return false; - } - participants.Add(p); - await raceChannel.SendMessage($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {NadekoBot.Config.CurrencyName.SnPl(amount)}!**" : "**")); - return true; - } - } + public IGuildUser User { get; set; } + public string Animal { get; set; } + public int AmountBet { get; set; } - public class Participant - { - public IGuildUser User { get; set; } - public string Animal { get; set; } - public int AmountBet { get; set; } + public float Coeff { get; set; } + public int Total { get; set; } - public float Coeff { get; set; } - public int Total { get; set; } + public int Place { get; set; } = 0; - public int Place { get; set; } = 0; - - public Participant(IGuildUser u, string a, int amount) - { - this.User = u; - this.Animal = a; - this.AmountBet = amount; - } - - public override int GetHashCode() - { - return User.GetHashCode(); - } - - public override bool Equals(object obj) - { - var p = obj as Participant; - return p == null ? - false : - p.User == User; - } - - public override string ToString() - { - var str = new string('โ€ฃ', Total) + Animal; - if (Place == 0) - return str; - if (Place == 1) + public Participant(IGuildUser u, string a, int amount) { - return str + "๐Ÿ†"; - } - else if (Place == 2) - { - return str + "`2nd`"; - } - else if (Place == 3) - { - return str + "`3rd`"; - } - else - { - return str + $"`{Place}th`"; + this.User = u; + this.Animal = a; + this.AmountBet = amount; } + public override int GetHashCode() + { + return User.GetHashCode(); + } + + public override bool Equals(object obj) + { + var p = obj as Participant; + return p == null ? + false : + p.User == User; + } + + public override string ToString() + { + var str = new string('โ€ฃ', Total) + Animal; + if (Place == 0) + return str; + if (Place == 1) + { + return str + "๐Ÿ†"; + } + else if (Place == 2) + { + return str + "`2nd`"; + } + else if (Place == 3) + { + return str + "`3rd`"; + } + else + { + return str + $"`{Place}th`"; + } + + } } } } -} +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index 732835e4..2cfb51cc 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -69,10 +69,10 @@ // IsActive = true; // CurrentSentence = SentencesProvider.GetRandomSentence(); // var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f); -// await channel.SendMessage($":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false); +// 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.SendMessage("Starting new typing contest in **3**...").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); diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 62fb82d5..746fcc56 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -63,7 +63,7 @@ // msg += $"\n`Here is the Link:`ใ€ http://www.beam.pro/{stream.Username}/ ใ€‘"; // else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) // msg += $"\n`Here is the Link:`ใ€ not implemented yet - {stream.Username} ใ€‘"; -// await channel.SendMessage(msg).ConfigureAwait(false); +// await channel.SendMessageAsync(msg).ConfigureAwait(false); // } // } // FirstPass = false; diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index 1dc2433c..3eaa2b37 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -61,7 +61,7 @@ // if (ch == null) // return; -// await ch.SendMessage( +// await ch.SendMessageAsync( // replacements.Aggregate(NadekoBot.Config.RemindMessageFormat, // (cur, replace) => cur.Replace(replace.Key, replace.Value(r))) // ).ConfigureAwait(false); //it works trust me diff --git a/src/NadekoBot/_Modules/Music/MusicModule.cs b/src/NadekoBot/_Modules/Music/MusicModule.cs index 77565411..ea9d136e 100644 --- a/src/NadekoBot/_Modules/Music/MusicModule.cs +++ b/src/NadekoBot/_Modules/Music/MusicModule.cs @@ -633,7 +633,7 @@ namespace NadekoBot.Modules.Music var textCh = e.Channel; if (voiceCh == null || voiceCh.Server != textCh.Server) { - await textCh.SendMessage("๐Ÿ’ข You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); + await textCh.SendMessageAsync("๐Ÿ’ข You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); return; } var name = e.GetArg("name")?.Trim().ToLowerInvariant(); @@ -812,7 +812,7 @@ namespace NadekoBot.Modules.Music if (voiceCh == null || voiceCh.Server != textCh.Server) { if (!silent) - await textCh.SendMessage("๐Ÿ’ข You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); + await textCh.SendMessageAsync("๐Ÿ’ข You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) @@ -836,7 +836,7 @@ namespace NadekoBot.Modules.Music await lastFinishedMessage.Delete().ConfigureAwait(false); if (playingMessage != null) await playingMessage.Delete().ConfigureAwait(false); - lastFinishedMessage = await textCh.SendMessage($"๐ŸŽต`Finished`{song.PrettyName}").ConfigureAwait(false); + lastFinishedMessage = await textCh.SendMessageAsync($"๐ŸŽต`Finished`{song.PrettyName}").ConfigureAwait(false); if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") { await QueueSong(queuer.Server.CurrentUser, textCh, voiceCh, (await SearchHelper.GetRelatedVideoIds(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false); @@ -860,7 +860,7 @@ namespace NadekoBot.Modules.Music { var msgTxt = $"๐ŸŽต`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; - playingMessage = await textCh.SendMessage(msgTxt).ConfigureAwait(false); + playingMessage = await textCh.SendMessageAsync(msgTxt).ConfigureAwait(false); } catch { } } @@ -877,12 +877,12 @@ namespace NadekoBot.Modules.Music } catch (PlaylistFullException) { - await textCh.SendMessage($"๐ŸŽต `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` "); + await textCh.SendMessageAsync($"๐ŸŽต `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` "); throw; } if (!silent) { - var queuedMessage = await textCh.SendMessage($"๐ŸŽต`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); + var queuedMessage = await textCh.SendMessageAsync($"๐ŸŽต`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async () => { diff --git a/src/NadekoBot/_Modules/Permissions/Commands/FilterInvitesCommand.cs b/src/NadekoBot/_Modules/Permissions/Commands/FilterInvitesCommand.cs index 47ba8b53..bc3a5134 100644 --- a/src/NadekoBot/_Modules/Permissions/Commands/FilterInvitesCommand.cs +++ b/src/NadekoBot/_Modules/Permissions/Commands/FilterInvitesCommand.cs @@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Permissions.Commands $"INVITE LINK in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" + $"`Full message:` {args.Message.Text}"); if (serverPerms.Verbose) - await args.Channel.SendMessage($"{args.User.Mention} Invite links are not " + + await args.Channel.SendMessageAsync($"{args.User.Mention} Invite links are not " + $"allowed on this channel.") .ConfigureAwait(false); } diff --git a/src/NadekoBot/_Modules/Permissions/Commands/FilterWordsCommand.cs b/src/NadekoBot/_Modules/Permissions/Commands/FilterWordsCommand.cs index bd16354d..86882cd4 100644 --- a/src/NadekoBot/_Modules/Permissions/Commands/FilterWordsCommand.cs +++ b/src/NadekoBot/_Modules/Permissions/Commands/FilterWordsCommand.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Permissions.Commands $"BANNED WORD in [{args.Channel.Name}/{args.Channel.Id}] channel.\n" + $"`Full message:` {args.Message.Text}"); if (serverPerms.Verbose) - await args.Channel.SendMessage($"{args.User.Mention} One or more of the words you used " + + await args.Channel.SendMessageAsync($"{args.User.Mention} One or more of the words you used " + $"in that sentence are not allowed here.") .ConfigureAwait(false); }