mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Auto delete the juice message
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Humanizer.Localisation;
|
using Humanizer.Localisation;
|
||||||
|
using KfChatDotNetBot.Models;
|
||||||
using KfChatDotNetBot.Models.DbModels;
|
using KfChatDotNetBot.Models.DbModels;
|
||||||
using KfChatDotNetBot.Settings;
|
using KfChatDotNetBot.Settings;
|
||||||
using KfChatDotNetWsClient.Models.Events;
|
using KfChatDotNetWsClient.Models.Events;
|
||||||
@@ -14,7 +15,7 @@ public class JuiceCommand : ICommand
|
|||||||
public string HelpText => "Get juice!";
|
public string HelpText => "Get juice!";
|
||||||
public bool HideFromHelp => false;
|
public bool HideFromHelp => false;
|
||||||
public UserRight RequiredRight => UserRight.Loser;
|
public UserRight RequiredRight => UserRight.Loser;
|
||||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
public TimeSpan Timeout => TimeSpan.FromSeconds(60);
|
||||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||||
{
|
{
|
||||||
await using var db = new ApplicationDbContext();
|
await using var db = new ApplicationDbContext();
|
||||||
@@ -24,7 +25,7 @@ public class JuiceCommand : ICommand
|
|||||||
var juicerSettings = await Helpers.GetMultipleValues([
|
var juicerSettings = await Helpers.GetMultipleValues([
|
||||||
BuiltIn.Keys.JuiceAmount, BuiltIn.Keys.JuiceCooldown, BuiltIn.Keys.JuiceLoserDivision,
|
BuiltIn.Keys.JuiceAmount, BuiltIn.Keys.JuiceCooldown, BuiltIn.Keys.JuiceLoserDivision,
|
||||||
BuiltIn.Keys.GambaSeshDetectEnabled, BuiltIn.Keys.JuiceAllowedWhileStreaming,
|
BuiltIn.Keys.GambaSeshDetectEnabled, BuiltIn.Keys.JuiceAllowedWhileStreaming,
|
||||||
BuiltIn.Keys.TwitchBossmanJackUsername
|
BuiltIn.Keys.TwitchBossmanJackUsername, BuiltIn.Keys.JuiceAutoDeleteMsgDelay
|
||||||
]);
|
]);
|
||||||
var cooldown = juicerSettings[BuiltIn.Keys.JuiceCooldown].ToType<int>();
|
var cooldown = juicerSettings[BuiltIn.Keys.JuiceCooldown].ToType<int>();
|
||||||
var amount = juicerSettings[BuiltIn.Keys.JuiceAmount].ToType<int>();
|
var amount = juicerSettings[BuiltIn.Keys.JuiceAmount].ToType<int>();
|
||||||
@@ -45,10 +46,21 @@ public class JuiceCommand : ICommand
|
|||||||
|
|
||||||
if (lastJuicer.Count == 0)
|
if (lastJuicer.Count == 0)
|
||||||
{
|
{
|
||||||
await botInstance.SendChatMessageAsync($"!juice {message.Author.Id} {amount}", true);
|
var sentMsg = await botInstance.SendChatMessageAsync($"!juice {message.Author.Id} {amount}", true);
|
||||||
await db.Juicers.AddAsync(new JuicerDbModel
|
await db.Juicers.AddAsync(new JuicerDbModel
|
||||||
{ Amount = amount, User = user, JuicedAt = DateTimeOffset.UtcNow }, ctx);
|
{ Amount = amount, User = user, JuicedAt = DateTimeOffset.UtcNow }, ctx);
|
||||||
await db.SaveChangesAsync(ctx);
|
await db.SaveChangesAsync(ctx);
|
||||||
|
if (juicerSettings[BuiltIn.Keys.JuiceAutoDeleteMsgDelay].Value == null) return;
|
||||||
|
var delay = int.Parse(juicerSettings[BuiltIn.Keys.JuiceAutoDeleteMsgDelay].Value!);
|
||||||
|
if (delay <= 0) return;
|
||||||
|
while (sentMsg.ChatMessageId == null)
|
||||||
|
{
|
||||||
|
if (sentMsg.Status is SentMessageTrackerStatus.Lost or SentMessageTrackerStatus.NotSending) return;
|
||||||
|
await Task.Delay(500, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(delay, ctx);
|
||||||
|
await botInstance.KfClient.DeleteMessageAsync(sentMsg.ChatMessageId.Value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -793,6 +793,17 @@ public static class BuiltIn
|
|||||||
IsSecret = false,
|
IsSecret = false,
|
||||||
CacheDuration = TimeSpan.FromHours(1),
|
CacheDuration = TimeSpan.FromHours(1),
|
||||||
ValueType = SettingValueType.Text
|
ValueType = SettingValueType.Text
|
||||||
|
},
|
||||||
|
new BuiltInSettingsModel
|
||||||
|
{
|
||||||
|
Key = Keys.JuiceAutoDeleteMsgDelay,
|
||||||
|
Regex = @"\d+",
|
||||||
|
Description = "Delay before deleting the !juice message in milliseconds, null or 0 to disable. " +
|
||||||
|
"Don't set too high as the timeout for !juiceme is 60 seconds",
|
||||||
|
Default = "2500",
|
||||||
|
IsSecret = false,
|
||||||
|
CacheDuration = TimeSpan.FromHours(1),
|
||||||
|
ValueType = SettingValueType.Text
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -866,5 +877,6 @@ public static class BuiltIn
|
|||||||
public static string JuiceAllowedWhileStreaming = "Juice.AllowedWhileStreaming";
|
public static string JuiceAllowedWhileStreaming = "Juice.AllowedWhileStreaming";
|
||||||
public static string BotImagePigCubeSelfDestruct = "Bot.Image.PigCubeSelfDestruct";
|
public static string BotImagePigCubeSelfDestruct = "Bot.Image.PigCubeSelfDestruct";
|
||||||
public static string BotImageInvertedCubeUrl = "Bot.Image.InvertedCubeUrl";
|
public static string BotImageInvertedCubeUrl = "Bot.Image.InvertedCubeUrl";
|
||||||
|
public static string JuiceAutoDeleteMsgDelay = "Juice.AutoDeleteMsgDelay";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user