clear out detiktokable links when done

fixes #18
This commit is contained in:
Adam R Grey 2023-08-22 14:58:44 -04:00
parent e9ddcd237c
commit da7078f535
3 changed files with 33 additions and 28 deletions

View File

@ -45,6 +45,7 @@ public class Behaver
{ {
behavior.ActOn(message); behavior.ActOn(message);
message.ActedOn = true; message.ActedOn = true;
Console.WriteLine("acted on, moving forward");
} }
} }
if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id)) if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.Selves.Any(acc => acc.Id == message.Author.Id))
@ -52,15 +53,11 @@ public class Behaver
Console.WriteLine("providing bullshit nonanswer / admitting uselessness"); Console.WriteLine("providing bullshit nonanswer / admitting uselessness");
var responses = new List<string>(){ var responses = new List<string>(){
@"Well, that's a great question, and there are certainly many different possible answers. Ultimately, the decision will depend on a variety of factors, including your personal interests and goals, as well as any practical considerations (like the economy). I encourage you to do your research, speak with experts and educators, and explore your options before making a decision that's right for you.", @"Well, that's a great question, and there are certainly many different possible answers. Ultimately, the decision will depend on a variety of factors, including your personal interests and goals, as well as any practical considerations (like the economy). I encourage you to do your research, speak with experts and educators, and explore your options before making a decision that's right for you.",
@"┐(゚ ~゚ )┌",@"¯\_(ツ)_/¯",@"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭" @"┐(゚ ~゚ )┌", @"¯\_(ツ)_/¯", @"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭"
}; };
await message.Channel.SendMessage(responses[Shared.r.Next(responses.Count)]); await message.Channel.SendMessage(responses[Shared.r.Next(responses.Count)]);
message.ActedOn = true; message.ActedOn = true;
} }
if (message.ActedOn)
{
_db.SaveChanges();
}
return message.ActedOn; return message.ActedOn;
} }
} }

View File

@ -44,12 +44,16 @@ public class Detiktokify : Behavior
} }
} }
} }
if(tiktokLinks.Any()){
Console.WriteLine($"Should Act on message id {message.ExternalId}; with content {message.Content}");
}
return tiktokLinks.Any(); return tiktokLinks.Any();
} }
public override async Task<bool> ActOn(Message message) public override async Task<bool> ActOn(Message message)
{ {
foreach(var link in tiktokLinks) foreach(var link in tiktokLinks)
{ {
tiktokLinks.Remove(link);
try try
{ {
Console.WriteLine($"detiktokifying {link}"); Console.WriteLine($"detiktokifying {link}");

View File

@ -92,30 +92,34 @@ public class TwitchInterface
private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e) private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e)
{ {
Console.WriteLine($"whisper#{e.WhisperMessage.Username}[{DateTime.Now}][{e.WhisperMessage.DisplayName} [id={e.WhisperMessage.Username}]][msg id: {e.WhisperMessage.MessageId}] {e.WhisperMessage.Message}"); Console.WriteLine($"whisper#{e.WhisperMessage.Username}[{DateTime.Now}][{e.WhisperMessage.DisplayName} [id={e.WhisperMessage.Username}]][msg id: {e.WhisperMessage.MessageId}] {e.WhisperMessage.Message}");
if (_db.Messages.Select(m => m.ExternalId == e.WhisperMessage.MessageId) != null)
{
Console.WriteLine("already seent it");
return;
}
var m = UpsertMessage(e.WhisperMessage); var m = UpsertMessage(e.WhisperMessage);
m.Channel.IsDM = true; m.Channel.IsDM = true;
m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b"); m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b");
_db.SaveChanges();
if (await Behaver.Instance.ActOn(m)) await Behaver.Instance.ActOn(m);
{
m.ActedOn = true;
}
_db.SaveChanges(); _db.SaveChanges();
} }
private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e) private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e)
{ {
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}");
if (_db.Messages.Select(m => m.ExternalId == e.ChatMessage.Id) != null)
{
Console.WriteLine("already seent it");
return;
}
var m = UpsertMessage(e.ChatMessage); var m = UpsertMessage(e.ChatMessage);
m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") || m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") ||
e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername; e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername;
_db.SaveChanges();
if (await Behaver.Instance.ActOn(m)) await Behaver.Instance.ActOn(m);
{
m.ActedOn = true;
}
_db.SaveChanges(); _db.SaveChanges();
} }
@ -154,10 +158,10 @@ public class TwitchInterface
//acc.IsBot = //acc.IsBot =
acc.Protocol = PROTOCOL; acc.Protocol = PROTOCOL;
if(hadToAdd) if (hadToAdd)
{ {
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol)); acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
if(acc.IsUser == null) if (acc.IsUser == null)
{ {
acc.IsUser = new vassago.Models.User() { Accounts = new List<Account>() { acc } }; acc.IsUser = new vassago.Models.User() { Accounts = new List<Account>() { acc } };
_db.Users.Add(acc.IsUser); _db.Users.Add(acc.IsUser);
@ -181,7 +185,7 @@ public class TwitchInterface
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(() => {client.SendMessage(channelName, t); }); }; c.SendMessage = (t) => { return Task.Run(() => { client.SendMessage(channelName, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
return c; return c;
throw new NotImplementedException(); throw new NotImplementedException();
@ -201,7 +205,7 @@ public class TwitchInterface
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(() => {client.SendWhisper(whisperWith, t); }); }; c.SendMessage = (t) => { return Task.Run(() => { client.SendWhisper(whisperWith, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
return c; return c;
throw new NotImplementedException(); throw new NotImplementedException();
@ -214,7 +218,7 @@ public class TwitchInterface
{ {
m = new Message(); m = new Message();
_db.Messages.Add(m); _db.Messages.Add(m);
m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); m.Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc);
} }
m.Content = chatMessage.Message; m.Content = chatMessage.Message;
@ -234,7 +238,7 @@ public class TwitchInterface
{ {
m = new Message(); m = new Message();
_db.Messages.Add(m); _db.Messages.Add(m);
m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); m.Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc);
} }
m.Content = whisperMessage.Message; m.Content = whisperMessage.Message;
@ -244,7 +248,7 @@ public class TwitchInterface
m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id); m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id);
m.Author.SeenInChannel = m.Channel; m.Author.SeenInChannel = m.Channel;
m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });}; m.Reply = (t) => { return Task.Run(() => { client.SendWhisper(whisperMessage.Username, t); }); };
m.React = (e) => { throw new InvalidOperationException($"twitch cannot react"); }; m.React = (e) => { throw new InvalidOperationException($"twitch cannot react"); };
return m; return m;
} }