diff --git a/UPBot Code/Commands/Game.cs b/UPBot Code/Commands/Game.cs index 8cd41c3..5c78672 100644 --- a/UPBot Code/Commands/Game.cs +++ b/UPBot Code/Commands/Game.cs @@ -59,35 +59,35 @@ public async Task RPSCommand(CommandContext ctx) { await ctx.Channel.DeleteMessageAsync(msg); if (ir.Id == "idrock") { if(val == 0) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played 🪨 Rock! **DRAW!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played 🪨 Rock! **DRAW!**"); } else if(val == 1) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played 📄 Paper! **I win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played 📄 Paper! **I win!**"); } else if(val == 2) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played ✂️ Scissor! **You win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played ✂️ Scissor! **You win!**"); } } else if (ir.Id == "idpaper") { if(val == 0) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played 🪨 Rock! **You win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played 🪨 Rock! **You win!**"); } else if(val == 1) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played 📄 Paper! **DRAW!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played 📄 Paper! **DRAW!**"); } else if(val == 2) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played ✂️ Scissor! **I win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played ✂️ Scissor! **I win!**"); } } else if (ir.Id == "idscissors") { if(val == 0) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played 🪨 Rock! **I win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played 🪨 Rock! **I win!**"); } else if(val == 1) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played 📄 Paper! **You win!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played 📄 Paper! **You win!**"); } else if(val == 2) { - await Utils.DeleteDelayed(15, await ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played ✂️ Scissor! **DRAW!**")); + await Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played ✂️ Scissor! **DRAW!**"); } } } @@ -136,27 +136,27 @@ Task PlayRockPaperScissors(CommandContext ctx, string kind) { if (playerChoice == RPSTypes.Rock) { if (botChoice == RPSTypes.Rock) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played 🪨 Rock! **DRAW!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played 🪨 Rock! **DRAW!**"); } else if (botChoice == RPSTypes.Paper) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played 📄 Paper! **I win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played 📄 Paper! **I win!**"); } else { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 🪨 Rock " + ctx.Member.Mention + ", I played ✂️ Scissor! **You win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 🪨 Rock " + ctx.Member.Mention + ", I played ✂️ Scissor! **You win!**"); } } else if (playerChoice == RPSTypes.Paper) { if (botChoice == RPSTypes.Rock) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played 🪨 Rock! **You win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played 🪨 Rock! **You win!**"); } else if (botChoice == RPSTypes.Paper) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played 📄 Paper! **DRAW!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played 📄 Paper! **DRAW!**"); } else { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said 📄 Paper " + ctx.Member.Mention + ", I played ✂️ Scissor! **I win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said 📄 Paper " + ctx.Member.Mention + ", I played ✂️ Scissor! **I win!**"); } } else { if (botChoice == RPSTypes.Rock) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played 🪨 Rock! **I win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played 🪨 Rock! **I win!**"); } else if (botChoice == RPSTypes.Paper) { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played 📄 Paper! **You win!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played 📄 Paper! **You win!**"); } else { - return Utils.DeleteDelayed(15, ctx.Channel.SendMessageAsync("You said ✂️ Scissor " + ctx.Member.Mention + ", I played ✂️ Scissor! **DRAW!**")); + return Utils.DeleteDelayedSend(15, ctx.Channel, "You said ✂️ Scissor " + ctx.Member.Mention + ", I played ✂️ Scissor! **DRAW!**"); } } } diff --git a/UPBot Code/Commands/Stats.cs b/UPBot Code/Commands/Stats.cs index 8cc00f6..6a5b87f 100644 --- a/UPBot Code/Commands/Stats.cs +++ b/UPBot Code/Commands/Stats.cs @@ -69,28 +69,28 @@ async Task GenerateStats(CommandContext ctx, string cmd, DiscordChannel ch) { var msg = await ctx.Channel.SendMessageAsync("Counting emojis usage, mentioned users and roles for the channel..."); string res = await CalculateAll(ctx, ch); await Utils.DeleteDelayed(60, ctx.Message); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (cmd == "emojis") { var msg = await ctx.Channel.SendMessageAsync("Counting emojis usage, mentioned users and roles for the channel..."); string res = await CalculateEmojis(ctx, ch); _ = msg.DeleteAsync(); await Utils.DeleteDelayed(60, ctx.Message); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (cmd == "users") { var msg = await ctx.Channel.SendMessageAsync("Counting mentioned people..."); string res = await CalculateUserMentions(ctx, ch); _ = msg.DeleteAsync(); await Utils.DeleteDelayed(60, ctx.Message); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (cmd == "roles") { var msg = await ctx.Channel.SendMessageAsync("Counting mentioned roles..."); string res = await CalculateRoleMentions(ctx, ch); _ = msg.DeleteAsync(); await Utils.DeleteDelayed(60, ctx.Message); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } } catch (Exception ex) { await ctx.RespondAsync(Utils.GenerateErrorAnswer(ctx.Guild.Name, "Stats", ex)); @@ -179,28 +179,28 @@ public async Task GenerateStatsInteractive(CommandContext ctx) { msg = await ctx.Channel.SendMessageAsync("Counting emojis usage, mentioned users and roles for the channel..."); string res = await CalculateAll(ctx, ctx.Channel); msg.DeleteAsync().Wait(); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (ir.Id == "idusedemojis") { msg.DeleteAsync().Wait(); msg = await ctx.Channel.SendMessageAsync("Counting emojis usage for the channel..."); string res = await CalculateEmojis(ctx, ctx.Channel); msg.DeleteAsync().Wait(); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (ir.Id == "idmentionedusers") { msg.DeleteAsync().Wait(); msg = await ctx.Channel.SendMessageAsync("Counting mentioned people..."); string res = await CalculateUserMentions(ctx, ctx.Channel); msg.DeleteAsync().Wait(); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else if (ir.Id == "idmentionedroles") { msg.DeleteAsync().Wait(); msg = await ctx.Channel.SendMessageAsync("Counting mentioned roles..."); string res = await CalculateRoleMentions(ctx, ctx.Channel); msg.DeleteAsync().Wait(); - await Utils.DeleteDelayed(120, ctx.Channel.SendMessageAsync(res)); + await Utils.DeleteDelayedSend(120, ctx.Channel, res); } else { await Utils.DeleteDelayed(120, ctx.Message); diff --git a/UPBot Code/Utils.cs b/UPBot Code/Utils.cs index 428535b..73f24e1 100644 --- a/UPBot Code/Utils.cs +++ b/UPBot Code/Utils.cs @@ -413,6 +413,27 @@ public static Task DeleteDelayed(int seconds, DiscordMessage msg1) { Task.Run(() => DelayAfterAWhile(msg1, seconds * 1000)); return Task.FromResult(0); } + public static Task DeleteDelayedSend(int seconds, DiscordChannel ch, string msg) { + if (msg.Length > 1999) { // Split + List msgs = new List(); + while (msg.Length > 1999) { + int pos = msg.LastIndexOf(' ', 2000); + if (pos == -1) pos = 1990; + string msg1 = msg[0..pos].Trim(); + msg = msg[pos..].Trim(); + msgs.Add(ch.SendMessageAsync(msg1).Result); + } + if (msg.Length > 0) msgs.Add(ch.SendMessageAsync(msg).Result); + foreach (var dm in msgs) { + Task.Run(() => DelayAfterAWhile(dm, seconds * 1000)); + } + } + else { + DiscordMessage dmsg = ch.SendMessageAsync(msg).Result; + Task.Run(() => DelayAfterAWhile(dmsg, seconds * 1000)); + } + return Task.FromResult(0); + } /// /// Used to delete some messages after a while