forked from adam/discord-bot-shtik
kafka messages include UAC match
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
This commit is contained in:
parent
072a76794e
commit
6764acc55f
19
Behaver.cs
19
Behaver.cs
@ -43,16 +43,19 @@ public class Behaver
|
|||||||
|
|
||||||
public async Task<bool> ActOn(Message message)
|
public async Task<bool> ActOn(Message message)
|
||||||
{
|
{
|
||||||
|
var matchingUACs = Rememberer.MatchUACs(message);
|
||||||
var behaviorsActedOn = new List<string>();
|
var behaviorsActedOn = new List<string>();
|
||||||
foreach (var behavior in Behaviors)
|
foreach (var behavior in Behaviors)
|
||||||
{
|
{
|
||||||
if (behavior.ShouldAct(message))
|
//if (!behavior.ShouldAct(message, matchingUACs)) //TODO: this way
|
||||||
|
if(!behavior.ShouldAct(message))
|
||||||
{
|
{
|
||||||
behavior.ActOn(message);
|
continue;
|
||||||
message.ActedOn = true;
|
|
||||||
behaviorsActedOn.Add(behavior.ToString());
|
|
||||||
Console.WriteLine("acted on, moving forward");
|
|
||||||
}
|
}
|
||||||
|
behavior.ActOn(message);
|
||||||
|
message.ActedOn = true;
|
||||||
|
behaviorsActedOn.Add(behavior.ToString());
|
||||||
|
Console.WriteLine("acted on, moving forward");
|
||||||
}
|
}
|
||||||
if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.SelfAccounts.Any(acc => acc.Id == message.Author.Id))
|
if (message.ActedOn == false && message.MentionsMe && message.Content.Contains('?') && !Behaver.Instance.SelfAccounts.Any(acc => acc.Id == message.Author.Id))
|
||||||
{
|
{
|
||||||
@ -66,11 +69,11 @@ public class Behaver
|
|||||||
behaviorsActedOn.Add("generic question fallback");
|
behaviorsActedOn.Add("generic question fallback");
|
||||||
}
|
}
|
||||||
Rememberer.RememberMessage(message);
|
Rememberer.RememberMessage(message);
|
||||||
ForwardToKafka(message, behaviorsActedOn);
|
ForwardToKafka(message, behaviorsActedOn, matchingUACs);
|
||||||
return message.ActedOn;
|
return message.ActedOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ForwardToKafka(Message message, List<string> actedOnBy)
|
internal void ForwardToKafka(Message message, List<string> actedOnBy, List<UAC> matchingUACs)
|
||||||
{
|
{
|
||||||
var kafkaesque = new chat_message()
|
var kafkaesque = new chat_message()
|
||||||
{
|
{
|
||||||
@ -92,7 +95,7 @@ public class Behaver
|
|||||||
ChannelName = message.Channel.DisplayName,
|
ChannelName = message.Channel.DisplayName,
|
||||||
ChannelProtoocl = message.Channel.Protocol,
|
ChannelProtoocl = message.Channel.Protocol,
|
||||||
|
|
||||||
UAC_Matches = null,
|
UAC_Matches = matchingUACs.Select(uac => uac.Id).ToList(),
|
||||||
BehavedOnBy = actedOnBy
|
BehavedOnBy = actedOnBy
|
||||||
};
|
};
|
||||||
Telefranz.Instance.ProduceMessage(kafkaesque);
|
Telefranz.Instance.ProduceMessage(kafkaesque);
|
||||||
|
@ -14,10 +14,10 @@ namespace vassago
|
|||||||
{
|
{
|
||||||
Shared.DBConnectionString = aspConfig["DBConnectionString"];
|
Shared.DBConnectionString = aspConfig["DBConnectionString"];
|
||||||
Shared.SetupSlashCommands = aspConfig["SetupSlashCommands"]?.ToLower() == "true";
|
Shared.SetupSlashCommands = aspConfig["SetupSlashCommands"]?.ToLower() == "true";
|
||||||
|
Shared.API_URL = new Uri(aspConfig["API_URL"]);
|
||||||
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
||||||
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
||||||
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
|
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
|
||||||
|
|
||||||
Telefranz.Configure(aspConfig["KafkaName"], aspConfig["KafkaBootstrap"]);
|
Telefranz.Configure(aspConfig["KafkaName"], aspConfig["KafkaBootstrap"]);
|
||||||
vassago.Behavior.Webhook.SetupWebhooks(aspConfig.GetSection("Webhooks"));
|
vassago.Behavior.Webhook.SetupWebhooks(aspConfig.GetSection("Webhooks"));
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ public class Message
|
|||||||
public Account Author { get; set; }
|
public Account Author { get; set; }
|
||||||
public Channel Channel { get; set; }
|
public Channel Channel { get; set; }
|
||||||
|
|
||||||
|
|
||||||
//TODO: these are nicities to make it OOP, but it couples them with their respective platform interfaces (and connections!)
|
//TODO: these are nicities to make it OOP, but it couples them with their respective platform interfaces (and connections!)
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public Func<string, Task> Reply;
|
public Func<string, Task> Reply;
|
||||||
|
@ -209,6 +209,7 @@ public class DiscordInterface
|
|||||||
var m = Rememberer.SearchMessage(mi => mi.ExternalId == dMessage.Id.ToString() && mi.Protocol == PROTOCOL)
|
var m = Rememberer.SearchMessage(mi => mi.ExternalId == dMessage.Id.ToString() && mi.Protocol == PROTOCOL)
|
||||||
?? new()
|
?? new()
|
||||||
{
|
{
|
||||||
|
//I don't understand why messages need to have their Ids specified but no other entity does. shrug dot emoji
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
Protocol = PROTOCOL
|
Protocol = PROTOCOL
|
||||||
};
|
};
|
||||||
|
@ -291,6 +291,7 @@ public class TwitchInterface
|
|||||||
var m = Rememberer.SearchMessage(mi => mi.ExternalId == whisperMessage.MessageId && mi.Protocol == PROTOCOL)
|
var m = Rememberer.SearchMessage(mi => mi.ExternalId == whisperMessage.MessageId && mi.Protocol == PROTOCOL)
|
||||||
?? new()
|
?? new()
|
||||||
{
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
Protocol = PROTOCOL,
|
Protocol = PROTOCOL,
|
||||||
Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc)
|
Timestamp = (DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc)
|
||||||
};
|
};
|
||||||
|
@ -179,6 +179,17 @@ public static class Rememberer
|
|||||||
dbAccessSemaphore.Release();
|
dbAccessSemaphore.Release();
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
public static List<UAC> MatchUACs(Message message)
|
||||||
|
{
|
||||||
|
var msgId = message.Id;
|
||||||
|
var accId = message.Author.Id;
|
||||||
|
var usrId = message.Author.IsUser.Id;
|
||||||
|
var chId = message.Channel.Id;
|
||||||
|
|
||||||
|
return SearchUACs(uac => uac.AccountInChannels.FirstOrDefault(aic => aic.Id == accId) != null
|
||||||
|
|| uac.Users.FirstOrDefault(usr => usr.Id == usrId) != null
|
||||||
|
|| uac.Channels.FirstOrDefault(ch => ch.Id == chId) != null);
|
||||||
|
}
|
||||||
public static List<UAC> SearchUACs(Expression<Func<UAC, bool>> predicate)
|
public static List<UAC> SearchUACs(Expression<Func<UAC, bool>> predicate)
|
||||||
{
|
{
|
||||||
List<UAC> toReturn;
|
List<UAC> toReturn;
|
||||||
|
@ -23,5 +23,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"KafkaBootstrap":"http://localhost:9092",
|
"KafkaBootstrap":"http://localhost:9092",
|
||||||
"KafkaName":"vassago"
|
"KafkaName":"vassago",
|
||||||
|
"API_URL": "http://localhost:5093/api"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user