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);
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))
@ -52,15 +53,11 @@ public class Behaver
Console.WriteLine("providing bullshit nonanswer / admitting uselessness");
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.",
@"┐(゚ ~゚ )┌",@"¯\_(ツ)_/¯",@"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭"
@"┐(゚ ~゚ )┌", @"¯\_(ツ)_/¯", @"╮ (. ❛ ᴗ ❛.) ╭", @"╮(╯ _╰ )╭"
};
await message.Channel.SendMessage(responses[Shared.r.Next(responses.Count)]);
message.ActedOn = true;
}
if (message.ActedOn)
{
_db.SaveChanges();
}
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();
}
public override async Task<bool> ActOn(Message message)
{
foreach(var link in tiktokLinks)
{
tiktokLinks.Remove(link);
try
{
Console.WriteLine($"detiktokifying {link}");

View File

@ -69,10 +69,10 @@ public class TwitchInterface
await SetupTwitchChannel();
WebSocketClient customClient = new WebSocketClient(new ClientOptions
{
MessagesAllowedInPeriod = 750,
ThrottlingPeriod = TimeSpan.FromSeconds(30)
}
{
MessagesAllowedInPeriod = 750,
ThrottlingPeriod = TimeSpan.FromSeconds(30)
}
);
client = new TwitchClient(customClient);
client.Initialize(new ConnectionCredentials(tc.username, tc.oauth, capabilities: new Capabilities()));
@ -92,30 +92,34 @@ public class TwitchInterface
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}");
if (_db.Messages.Select(m => m.ExternalId == e.WhisperMessage.MessageId) != null)
{
Console.WriteLine("already seent it");
return;
}
var m = UpsertMessage(e.WhisperMessage);
m.Channel.IsDM = true;
m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b");
_db.SaveChanges();
if (await Behaver.Instance.ActOn(m))
{
m.ActedOn = true;
}
await Behaver.Instance.ActOn(m);
_db.SaveChanges();
}
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}");
if (_db.Messages.Select(m => m.ExternalId == e.ChatMessage.Id) != null)
{
Console.WriteLine("already seent it");
return;
}
var m = UpsertMessage(e.ChatMessage);
m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") ||
e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername;
_db.SaveChanges();
if (await Behaver.Instance.ActOn(m))
{
m.ActedOn = true;
}
await Behaver.Instance.ActOn(m);
_db.SaveChanges();
}
@ -154,10 +158,10 @@ public class TwitchInterface
//acc.IsBot =
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));
if(acc.IsUser == null)
if (acc.IsUser == null)
{
acc.IsUser = new vassago.Models.User() { Accounts = new List<Account>() { acc } };
_db.Users.Add(acc.IsUser);
@ -181,8 +185,8 @@ public class TwitchInterface
c.Protocol = PROTOCOL;
c.ParentChannel = protocolAsChannel;
c.SubChannels = c.SubChannels ?? new List<Channel>();
c.SendMessage = (t) => { return Task.Run(() => {client.SendMessage(channelName, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
c.SendMessage = (t) => { return Task.Run(() => { client.SendMessage(channelName, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
return c;
throw new NotImplementedException();
}
@ -201,8 +205,8 @@ public class TwitchInterface
c.Protocol = PROTOCOL;
c.ParentChannel = protocolAsChannel;
c.SubChannels = c.SubChannels ?? new List<Channel>();
c.SendMessage = (t) => { return Task.Run(() => {client.SendWhisper(whisperWith, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
c.SendMessage = (t) => { return Task.Run(() => { client.SendWhisper(whisperWith, t); }); };
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
return c;
throw new NotImplementedException();
}
@ -214,7 +218,7 @@ public class TwitchInterface
{
m = new Message();
_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;
@ -234,7 +238,7 @@ public class TwitchInterface
{
m = new Message();
_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;
@ -244,7 +248,7 @@ public class TwitchInterface
m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id);
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"); };
return m;
}