probably fix twitchsummon

This commit is contained in:
adam 2025-05-01 11:18:02 -04:00
parent 0580a9d21f
commit e0283e87f5
4 changed files with 54 additions and 31 deletions

View File

@ -95,6 +95,16 @@ public class Behaver
a.IsUser = primary;
}
secondary.Accounts.Clear();
var uacs = Rememberer.SearchUACs(u => u.Users.FirstOrDefault(u => u.Id == secondary.Id) != null);
if (uacs.Count() > 0)
{
foreach (var uac in uacs)
{
uac.Users.RemoveAll(u => u.Id == secondary.Id);
uac.Users.Add(primary);
Rememberer.RememberUAC(uac);
}
}
Rememberer.ForgetUser(secondary);
Rememberer.RememberUser(primary);
return true;

View File

@ -14,7 +14,7 @@ public class TwitchDismiss : Behavior
public override bool ShouldAct(Message message)
{
var ti = ProtocolInterfaces.ProtocolList.twitchs.FirstOrDefault();
Console.WriteLine($"TwitchDismiss checking. menions me? {message.MentionsMe}");
// Console.WriteLine($"TwitchDismiss checking. menions me? {message.MentionsMe}");
if(message.MentionsMe &&
(Regex.IsMatch(message.Content.ToLower(), "\\bbegone\\b") || Regex.IsMatch(message.Content.ToLower(), "\\bfuck off\\b")))
{

View File

@ -142,14 +142,15 @@ public class TwitchInterface
private Account UpsertAccount(string username, Channel inChannel)
{
Console.WriteLine($"upserting twitch account. username: {username}. inChannel: {inChannel?.Id}");
//Console.WriteLine($"upserting twitch account. username: {username}. inChannel: {inChannel?.Id}");
var acc = Rememberer.SearchAccount(ui => ui.ExternalId == username && ui.SeenInChannel.ExternalId == inChannel.ExternalId);
Console.WriteLine($"upserting twitch account, retrieved {acc?.Id}.");
// Console.WriteLine($"upserting twitch account, retrieved {acc?.Id}.");
if (acc != null)
{
Console.WriteLine($"acc's usser: {acc.IsUser?.Id}");
}
acc ??= new Account() {
acc ??= new Account()
{
IsUser = Rememberer.SearchUser(
u => u.Accounts.Any(a => a.ExternalId == username && a.Protocol == PROTOCOL))
?? new vassago.Models.User()
@ -161,16 +162,16 @@ public class TwitchInterface
acc.Protocol = PROTOCOL;
acc.SeenInChannel = inChannel;
Console.WriteLine($"we asked rememberer to search for acc's user. {acc.IsUser?.Id}");
if (acc.IsUser != null)
{
Console.WriteLine($"user has record of {acc.IsUser.Accounts?.Count ?? 0} accounts");
}
// Console.WriteLine($"we asked rememberer to search for acc's user. {acc.IsUser?.Id}");
// if (acc.IsUser != null)
// {
// Console.WriteLine($"user has record of {acc.IsUser.Accounts?.Count ?? 0} accounts");
// }
acc.IsUser ??= new vassago.Models.User() { Accounts = [acc] };
if (inChannel.Users?.Count > 0)
{
Console.WriteLine($"channel has {inChannel.Users.Count} accounts");
}
// if (inChannel.Users?.Count > 0)
// {
// Console.WriteLine($"channel has {inChannel.Users.Count} accounts");
// }
Rememberer.RememberAccount(acc);
inChannel.Users ??= [];
if (!inChannel.Users.Contains(acc))
@ -187,7 +188,7 @@ public class TwitchInterface
&& ci.Protocol == PROTOCOL);
if (c == null)
{
Console.WriteLine($"couldn't find channel under protocol {PROTOCOL} with externalId {channelName}");
// Console.WriteLine($"couldn't find channel under protocol {PROTOCOL} with externalId {channelName}");
c = new Channel()
{
Users = []
@ -219,7 +220,7 @@ Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}"
&& ci.Protocol == PROTOCOL);
if (c == null)
{
Console.WriteLine($"couldn't find channel under protocol {PROTOCOL}, whisper with {whisperWith}");
// Console.WriteLine($"couldn't find channel under protocol {PROTOCOL}, whisper with {whisperWith}");
c = new Channel()
{
Users = []
@ -233,7 +234,10 @@ Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}"
c.Protocol = PROTOCOL;
c.ParentChannel = protocolAsChannel;
c.SubChannels = c.SubChannels ?? new List<Channel>();
c.SendMessage = (t) => { return Task.Run(() => {
c.SendMessage = (t) =>
{
return Task.Run(() =>
{
try
{

View File

@ -179,6 +179,15 @@ public static class Rememberer
dbAccessSemaphore.Release();
return toReturn;
}
public static List<UAC> SearchUACs(Expression<Func<UAC, bool>> predicate)
{
List<UAC> toReturn;
dbAccessSemaphore.Wait();
toReturn = db.UACs.Include(uac => uac.Users).Include(uac => uac.Channels).Include(uac => uac.AccountInChannels)
.Where(predicate).ToList();
dbAccessSemaphore.Release();
return toReturn;
}
public static void RememberUAC(UAC toRemember)
{
dbAccessSemaphore.Wait();