mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added Parti stream integration
This commit is contained in:
@@ -156,6 +156,74 @@ public class ReconnectKickCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
public class NewPartiChannelCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin parti add (?<forum_id>\d+) (?<social>\S+) (?<username>\S+) (?<auto_capture>true|false)$"),
|
||||
new Regex(@"^admin parti add (?<forum_id>\d+) (?<social>\S+) (?<username>\S+)$")
|
||||
|
||||
];
|
||||
|
||||
public string? HelpText => "Add a Parti channel to the bot's database";
|
||||
public UserRight RequiredRight => UserRight.Admin;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var autoCapture = false;
|
||||
if (arguments.TryGetValue("auto_capture", out var argument))
|
||||
{
|
||||
autoCapture = argument.Value == "true";
|
||||
}
|
||||
var channels = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.PartiChannels)).JsonDeserialize<List<PartiChannelModel>>();
|
||||
var username = arguments["username"].Value;
|
||||
channels ??= [];
|
||||
if (channels.Any(channel => channel.Username == username))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Channel is already in the database", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var forumId = Convert.ToInt32(arguments["forum_id"].Value);
|
||||
channels.Add(new PartiChannelModel
|
||||
{
|
||||
Username = username,
|
||||
ForumId = forumId,
|
||||
AutoCapture = autoCapture,
|
||||
SocialMedia = arguments["social"].Value
|
||||
});
|
||||
|
||||
await SettingsProvider.SetValueAsJsonObjectAsync(BuiltIn.Keys.PartiChannels, channels);
|
||||
await botInstance.SendChatMessageAsync("Updated list of channels", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class RemovePartiChannelCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin parti remove (?<username>\S+)$")
|
||||
];
|
||||
|
||||
public string? HelpText => "Remove a Parti channel from the bot's database";
|
||||
public UserRight RequiredRight => UserRight.Admin;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var channels = (await SettingsProvider.GetValueAsync(BuiltIn.Keys.PartiChannels)).JsonDeserialize<List<PartiChannelModel>>();
|
||||
if (channels == null) throw new Exception("Caught a null when deserializing Parti channels");
|
||||
var username = arguments["username"].Value;
|
||||
var channel = channels.FirstOrDefault(ch => ch.Username == username);
|
||||
if (channel == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Channel is not in the database", true);
|
||||
return;
|
||||
}
|
||||
channels.Remove(channel);
|
||||
|
||||
await SettingsProvider.SetValueAsJsonObjectAsync(BuiltIn.Keys.PartiChannels, channels);
|
||||
await botInstance.SendChatMessageAsync("Updated list of channels", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class AddCourtHearingCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
|
||||
@@ -74,25 +74,33 @@ public class SelfPromoCommand : ICommand
|
||||
CancellationToken ctx)
|
||||
{
|
||||
var channels = SettingsProvider.GetValueAsync(BuiltIn.Keys.KickChannels).Result.JsonDeserialize<List<KickChannelModel>>();
|
||||
if (channels == null)
|
||||
var partiChannels = SettingsProvider.GetValueAsync(BuiltIn.Keys.PartiChannels).Result
|
||||
.JsonDeserialize<List<PartiChannelModel>>();
|
||||
if (channels == null || partiChannels == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("For some reason the list of Kick channels deserialized to null", true);
|
||||
await botInstance.SendChatMessageAsync("For some reason the list of Kick or Parti channels deserialized to null", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var userChannels = channels.Where(ch => ch.ForumId == user.KfId).ToList();
|
||||
if (userChannels.Count == 0)
|
||||
var userPartiChannels = partiChannels.Where(ch => ch.ForumId == user.KfId).ToList();
|
||||
|
||||
if (userChannels.Count == 0 && userPartiChannels.Count == 0)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("You have no streams.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (userChannels.Count == 1)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync($"@{user.KfUsername} is a weirdo who streams. Come check out his channel at https://kick.com/{userChannels[0].ChannelSlug}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var streamList = userChannels.Aggregate(string.Empty, (current, stream) => current + $"[br]- https://kick.com/{stream.ChannelSlug}");
|
||||
foreach (var stream in userPartiChannels)
|
||||
{
|
||||
var url = $"https://parti.com/creator/{stream.SocialMedia}/{stream.Username}/";
|
||||
if (stream.SocialMedia == "discord")
|
||||
{
|
||||
url += "0";
|
||||
}
|
||||
|
||||
streamList += $"[br]- {url}";
|
||||
}
|
||||
|
||||
await botInstance.SendChatMessageAsync(
|
||||
$"@{user.KfUsername} is a weirdo who streams a lot. His channels are at: {streamList}", true);
|
||||
|
||||
Reference in New Issue
Block a user