internal static async Task <bool> EndAsync(DiscordUser author, ulong id, string reason, bool disq = false) { if (await AnyAsync(id) == DuelState.None) { return(false); } Duel duel = duels.Find(d => d.duel.duelist1 == id || d.duel.duelist2 == id); if (duel != null) { ulong dlst1 = id == duel.duel.duelist1 ? duel.duel.duelist1 : duel.duel.duelist2, dlst2 = id == duel.duel.duelist1 ? duel.duel.duelist2 : duel.duel.duelist1; var c = await Program.bot.GetChannelAsync(Program.config.ChannelForDuels); DiscordMember mem1 = null, mem2 = null; try { mem1 = await c.Guild.GetMemberAsync(dlst1); } catch { } try { mem2 = await c.Guild.GetMemberAsync(dlst2); } catch { } await c.SendMessageAsync(string.Empty, false, Program.bot.GetEmbed($"The duel between **{mem1?.DisplayName}** and **{mem2?.DisplayName}** has interrupted!", disq ? $"**{mem1?.DisplayName}** was disqualified.\nReason: '{reason}'\n**{mem2?.DisplayName}** has won and gets **3** points." : $"Reason: '{reason}'")); await Duelists.UpdateAsync(dlst1, 0, 1, 0); await Duelists.UpdateAsync(dlst2, disq? 3 : 0, 1, disq? 1 : 0); await duel.DeleteAsync(); return(true); } return(false); }
async void TimerUpdate(object o) { duel.minutes -= 10; if (duel.minutes <= 0) { var c = await Program.bot.GetChannelAsync(Program.config.ChannelForDuels); DiscordMessage mess1 = null, mess2 = null; DiscordMember mem1 = null, mem2 = null; try { mess1 = await c.GetMessageAsync(duel.message1); } catch { } try { mess2 = await c.GetMessageAsync(duel.message2); } catch { } try { mem1 = await c.Guild.GetMemberAsync(duel.duelist1); } catch { } try { mem2 = await c.Guild.GetMemberAsync(duel.duelist2); } catch { } if (!duel.flag) { StringBuilder b = new StringBuilder(""); if (mess1 == null || mess2 == null) { if (mess1 != null) { b.Append($"\n**{mem1.DisplayName}** has won as his opponent did not finish his work on time!\nWinner gets **3** points."); await Duelists.UpdateAsync(duel.duelist1, 3, 1, 1); await Duelists.UpdateAsync(duel.duelist2, 0, 1, 0); } else if (mess2 != null) { b.Append($"\n**{mem2.DisplayName}** has won as his opponent did not finish his work on time!\nWinner gets **3** points."); await Duelists.UpdateAsync(duel.duelist2, 3, 1, 1); await Duelists.UpdateAsync(duel.duelist1, 0, 1, 0); } else { b.Append("\nBoth duelists did not finish their work on time and lost :("); await Duelists.UpdateAsync(duel.duelist2, 0, 1, 0); await Duelists.UpdateAsync(duel.duelist1, 0, 1, 0); } await DeleteAsync(); } else { b.Append("\nResults of the duel will be notified in **12 hours**."); duel.minutes = 720; duel.flag = true; await UpdateAsync(); } await c.SendMessageAsync(string.Empty, false, Program.bot.GetEmbed($"The duel between **{mem1?.DisplayName}** and **{mem2?.DisplayName}**", $"Time is over!{b.ToString()}")); } else { DiscordGuildEmoji upv = await c.Guild.GetEmojiAsync(604972398424621066u), dwnv = await c.Guild.GetEmojiAsync(604973811154288660u); int upvotes1 = (await mess1.GetReactionsAsync(upv)).Count - (await mess1.GetReactionsAsync(dwnv)).Count; int upvotes2 = (await mess2.GetReactionsAsync(upv)).Count - (await mess2.GetReactionsAsync(dwnv)).Count; if (upvotes1 > upvotes2) { await c.SendMessageAsync(string.Empty, false, Program.bot.GetEmbed($"The duel between **{mem1?.DisplayName}** and **{mem2?.DisplayName}** has concluded!", $"Count: **{upvotes1}** <:upvote:604972398424621066> vs **{upvotes2}** <:upvote:604972398424621066>.", $"**{mem1.DisplayName}** is winning!", "Winner gets **3** points.")); await Duelists.UpdateAsync(duel.duelist2, 0, 1, 0); await Duelists.UpdateAsync(duel.duelist1, 3, 1, 1); } else if (upvotes1 < upvotes2) { await c.SendMessageAsync(string.Empty, false, Program.bot.GetEmbed($"The duel between **{mem1?.DisplayName}** and **{mem2?.DisplayName}** has concluded!", $"Count: **{upvotes1}** <:upvote:604972398424621066> vs **{upvotes2}** <:upvote:604972398424621066>.", $"**{mem2.DisplayName}** is winning!", "Winner gets **3** points.")); await Duelists.UpdateAsync(duel.duelist1, 0, 1, 0); await Duelists.UpdateAsync(duel.duelist2, 3, 1, 1); } else { await c.SendMessageAsync(string.Empty, false, Program.bot.GetEmbed($"The duel between **{mem1?.DisplayName}** and **{mem2?.DisplayName}** has concluded!", $"Count: **{upvotes1}** <:upvote:604972398424621066> vs **{upvotes2}** <:upvote:604972398424621066>.", "It's a draw!", "Both duelists get **2** points.")); await Duelists.UpdateAsync(duel.duelist1, 2, 1, 0); await Duelists.UpdateAsync(duel.duelist2, 2, 1, 0); } await DeleteAsync(); } } else { await UpdateAsync(); } }