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

@ -20,7 +20,7 @@ public class Behaver
var subtypes = AppDomain.CurrentDomain.GetAssemblies() var subtypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes()) .SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(vassago.Behavior.Behavior)) && !type.IsAbstract && .Where(type => type.IsSubclassOf(typeof(vassago.Behavior.Behavior)) && !type.IsAbstract &&
type.GetCustomAttributes(typeof(StaticPlzAttribute),false)?.Any() == true) type.GetCustomAttributes(typeof(StaticPlzAttribute), false)?.Any() == true)
.ToList(); .ToList();
foreach (var subtype in subtypes) foreach (var subtype in subtypes)
@ -72,7 +72,7 @@ public class Behaver
public void MarkSelf(Account selfAccount) public void MarkSelf(Account selfAccount)
{ {
if(SelfUser == null) if (SelfUser == null)
{ {
SelfUser = selfAccount.IsUser; SelfUser = selfAccount.IsUser;
} }
@ -86,15 +86,25 @@ public class Behaver
public bool CollapseUsers(User primary, User secondary) public bool CollapseUsers(User primary, User secondary)
{ {
if(primary.Accounts == null) if (primary.Accounts == null)
primary.Accounts = new List<Account>(); primary.Accounts = new List<Account>();
if(secondary.Accounts != null) if (secondary.Accounts != null)
primary.Accounts.AddRange(secondary.Accounts); primary.Accounts.AddRange(secondary.Accounts);
foreach(var a in secondary.Accounts) foreach (var a in secondary.Accounts)
{ {
a.IsUser = primary; a.IsUser = primary;
} }
secondary.Accounts.Clear(); 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.ForgetUser(secondary);
Rememberer.RememberUser(primary); Rememberer.RememberUser(primary);
return true; return true;

View File

@ -14,7 +14,7 @@ public class TwitchDismiss : Behavior
public override bool ShouldAct(Message message) public override bool ShouldAct(Message message)
{ {
var ti = ProtocolInterfaces.ProtocolList.twitchs.FirstOrDefault(); 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 && if(message.MentionsMe &&
(Regex.IsMatch(message.Content.ToLower(), "\\bbegone\\b") || Regex.IsMatch(message.Content.ToLower(), "\\bfuck off\\b"))) (Regex.IsMatch(message.Content.ToLower(), "\\bbegone\\b") || Regex.IsMatch(message.Content.ToLower(), "\\bfuck off\\b")))
{ {

View File

@ -15,7 +15,7 @@ namespace vassago.TwitchInterface;
internal class unifiedTwitchMessage internal class unifiedTwitchMessage
{ {
public unifiedTwitchMessage(ChatMessage chatMessage){} public unifiedTwitchMessage(ChatMessage chatMessage) { }
} }
public class TwitchInterface public class TwitchInterface
@ -110,7 +110,7 @@ public class TwitchInterface
//data eived //data eived
Console.WriteLine($"#{e.ChatMessage.Channel}[{DateTime.Now}][{e.ChatMessage.DisplayName} [id={e.ChatMessage.Username}]][msg id: {e.ChatMessage.Id}] {e.ChatMessage.Message}"); Console.WriteLine($"#{e.ChatMessage.Channel}[{DateTime.Now}][{e.ChatMessage.DisplayName} [id={e.ChatMessage.Username}]][msg id: {e.ChatMessage.Id}] {e.ChatMessage.Message}");
//translate to internal, upsert //translate to internal, upsert
var m = UpsertMessage(e.ChatMessage); var m = UpsertMessage(e.ChatMessage);
m.Reply = (t) => { return Task.Run(() => { client.SendReply(e.ChatMessage.Channel, e.ChatMessage.Id, t); }); }; m.Reply = (t) => { return Task.Run(() => { client.SendReply(e.ChatMessage.Channel, e.ChatMessage.Id, t); }); };
m.Channel.ChannelType = vassago.Models.Enumerations.ChannelType.Normal; m.Channel.ChannelType = vassago.Models.Enumerations.ChannelType.Normal;
@ -142,14 +142,15 @@ public class TwitchInterface
private Account UpsertAccount(string username, Channel inChannel) 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); 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) if (acc != null)
{ {
Console.WriteLine($"acc's usser: {acc.IsUser?.Id}"); Console.WriteLine($"acc's usser: {acc.IsUser?.Id}");
} }
acc ??= new Account() { acc ??= new Account()
{
IsUser = Rememberer.SearchUser( IsUser = Rememberer.SearchUser(
u => u.Accounts.Any(a => a.ExternalId == username && a.Protocol == PROTOCOL)) u => u.Accounts.Any(a => a.ExternalId == username && a.Protocol == PROTOCOL))
?? new vassago.Models.User() ?? new vassago.Models.User()
@ -161,16 +162,16 @@ public class TwitchInterface
acc.Protocol = PROTOCOL; acc.Protocol = PROTOCOL;
acc.SeenInChannel = inChannel; acc.SeenInChannel = inChannel;
Console.WriteLine($"we asked rememberer to search for acc's user. {acc.IsUser?.Id}"); // Console.WriteLine($"we asked rememberer to search for acc's user. {acc.IsUser?.Id}");
if (acc.IsUser != null) // if (acc.IsUser != null)
{ // {
Console.WriteLine($"user has record of {acc.IsUser.Accounts?.Count ?? 0} accounts"); // Console.WriteLine($"user has record of {acc.IsUser.Accounts?.Count ?? 0} accounts");
} // }
acc.IsUser ??= new vassago.Models.User() { Accounts = [acc] }; acc.IsUser ??= new vassago.Models.User() { Accounts = [acc] };
if (inChannel.Users?.Count > 0) // if (inChannel.Users?.Count > 0)
{ // {
Console.WriteLine($"channel has {inChannel.Users.Count} accounts"); // Console.WriteLine($"channel has {inChannel.Users.Count} accounts");
} // }
Rememberer.RememberAccount(acc); Rememberer.RememberAccount(acc);
inChannel.Users ??= []; inChannel.Users ??= [];
if (!inChannel.Users.Contains(acc)) if (!inChannel.Users.Contains(acc))
@ -187,7 +188,7 @@ public class TwitchInterface
&& ci.Protocol == PROTOCOL); && ci.Protocol == PROTOCOL);
if (c == null) 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() c = new Channel()
{ {
Users = [] Users = []
@ -206,7 +207,7 @@ public class TwitchInterface
c = Rememberer.RememberChannel(c); c = Rememberer.RememberChannel(c);
var selfAccountInChannel = c.Users?.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId); var selfAccountInChannel = c.Users?.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId);
if(selfAccountInChannel == null) if (selfAccountInChannel == null)
{ {
selfAccountInChannel = UpsertAccount(selfAccountInProtocol.Username, c); selfAccountInChannel = UpsertAccount(selfAccountInProtocol.Username, c);
} }
@ -215,11 +216,11 @@ public class TwitchInterface
} }
private Channel UpsertDMChannel(string whisperWith) private Channel UpsertDMChannel(string whisperWith)
{ {
Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}" Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}"
&& ci.Protocol == PROTOCOL); && ci.Protocol == PROTOCOL);
if (c == null) 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() c = new Channel()
{ {
Users = [] Users = []
@ -233,29 +234,32 @@ Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}"
c.Protocol = PROTOCOL; c.Protocol = PROTOCOL;
c.ParentChannel = protocolAsChannel; c.ParentChannel = protocolAsChannel;
c.SubChannels = c.SubChannels ?? new List<Channel>(); c.SubChannels = c.SubChannels ?? new List<Channel>();
c.SendMessage = (t) => { return Task.Run(() => { c.SendMessage = (t) =>
{
return Task.Run(() =>
{
try try
{ {
client.SendWhisper(whisperWith, t); client.SendWhisper(whisperWith, t);
} }
catch(Exception e) catch (Exception e)
{ {
Console.Error.WriteLine(e); Console.Error.WriteLine(e);
} }
}); });
}; };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
c = Rememberer.RememberChannel(c); c = Rememberer.RememberChannel(c);
var selfAccountInChannel = c.Users.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId); var selfAccountInChannel = c.Users.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId);
if(selfAccountInChannel == null) if (selfAccountInChannel == null)
{ {
selfAccountInChannel = UpsertAccount(selfAccountInChannel.Username, c); selfAccountInChannel = UpsertAccount(selfAccountInChannel.Username, c);
} }
return c; return c;
} }
//n.b., I see you future adam. "we should unify these, they're redundant". //n.b., I see you future adam. "we should unify these, they're redundant".
//ah, but that's the trick, they aren't! twitchlib has a common base class, but //ah, but that's the trick, they aren't! twitchlib has a common base class, but

View File

@ -179,7 +179,16 @@ public static class Rememberer
dbAccessSemaphore.Release(); dbAccessSemaphore.Release();
return toReturn; return toReturn;
} }
public static void RememberUAC(UAC toRemember) 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(); dbAccessSemaphore.Wait();
db.Update(toRemember); db.Update(toRemember);