forked from adam/discord-bot-shtik
Compare commits
No commits in common. "6764acc55f8b641d964b1f76717e464beb51159f" and "c42d6d3bc5d03d6873f421f430494ea267ffc674" have entirely different histories.
6764acc55f
...
c42d6d3bc5
48
Behaver.cs
48
Behaver.cs
@ -1,7 +1,5 @@
|
|||||||
namespace vassago;
|
namespace vassago;
|
||||||
#pragma warning disable 4014
|
#pragma warning disable 4014 //the "not awaited" error
|
||||||
using gray_messages.chat;
|
|
||||||
using franz;//the "not awaited" error
|
|
||||||
using vassago.Behavior;
|
using vassago.Behavior;
|
||||||
using vassago.Models;
|
using vassago.Models;
|
||||||
using System;
|
using System;
|
||||||
@ -43,19 +41,14 @@ 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>();
|
|
||||||
foreach (var behavior in Behaviors)
|
foreach (var behavior in Behaviors)
|
||||||
{
|
{
|
||||||
//if (!behavior.ShouldAct(message, matchingUACs)) //TODO: this way
|
if (behavior.ShouldAct(message))
|
||||||
if(!behavior.ShouldAct(message))
|
|
||||||
{
|
{
|
||||||
continue;
|
behavior.ActOn(message);
|
||||||
|
message.ActedOn = true;
|
||||||
|
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,41 +59,10 @@ public class Behaver
|
|||||||
};
|
};
|
||||||
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;
|
||||||
behaviorsActedOn.Add("generic question fallback");
|
|
||||||
}
|
}
|
||||||
Rememberer.RememberMessage(message);
|
|
||||||
ForwardToKafka(message, behaviorsActedOn, matchingUACs);
|
|
||||||
return message.ActedOn;
|
return message.ActedOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ForwardToKafka(Message message, List<string> actedOnBy, List<UAC> matchingUACs)
|
|
||||||
{
|
|
||||||
var kafkaesque = new chat_message()
|
|
||||||
{
|
|
||||||
Api_Uri = Shared.API_URL,
|
|
||||||
MessageId = message.Id,
|
|
||||||
|
|
||||||
MessageContent = message.Content,
|
|
||||||
MentionsMe = message.MentionsMe,
|
|
||||||
Timestamp = message.Timestamp,
|
|
||||||
AttachmentCount = (uint)(message.Attachments?.Count() ?? 0),
|
|
||||||
|
|
||||||
AccountId = message.Author.Id,
|
|
||||||
AccountName = message.Author.DisplayName,
|
|
||||||
|
|
||||||
UserId = message.Author.IsUser.Id,
|
|
||||||
UserName = message.Author.IsUser.DisplayName,
|
|
||||||
|
|
||||||
ChannelId = message.Channel.Id,
|
|
||||||
ChannelName = message.Channel.DisplayName,
|
|
||||||
ChannelProtoocl = message.Channel.Protocol,
|
|
||||||
|
|
||||||
UAC_Matches = matchingUACs.Select(uac => uac.Id).ToList(),
|
|
||||||
BehavedOnBy = actedOnBy
|
|
||||||
};
|
|
||||||
Telefranz.Instance.ProduceMessage(kafkaesque);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal bool IsSelf(Guid AccountId)
|
internal bool IsSelf(Guid AccountId)
|
||||||
{
|
{
|
||||||
var acc = Rememberer.SearchAccount(a => a.Id == AccountId);
|
var acc = Rememberer.SearchAccount(a => a.Id == AccountId);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
namespace vassago
|
namespace vassago
|
||||||
{
|
{
|
||||||
using franz;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using vassago;
|
using vassago;
|
||||||
using vassago.Models;
|
using vassago.Models;
|
||||||
@ -14,11 +13,9 @@ 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"]);
|
|
||||||
vassago.Behavior.Webhook.SetupWebhooks(aspConfig.GetSection("Webhooks"));
|
vassago.Behavior.Webhook.SetupWebhooks(aspConfig.GetSection("Webhooks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using franz;
|
|
||||||
using gray_messages;
|
|
||||||
|
|
||||||
namespace gray_messages.chat
|
|
||||||
{
|
|
||||||
public class chat_message : gray_messages.message
|
|
||||||
{
|
|
||||||
//expect this to be the same every time
|
|
||||||
public Uri Api_Uri { get; set; }
|
|
||||||
public Guid MessageId { get; set; }
|
|
||||||
public string MessageContent { get; set; }
|
|
||||||
public bool MentionsMe { get; set; }
|
|
||||||
public DateTimeOffset Timestamp { get; set; }
|
|
||||||
public uint AttachmentCount { get; set; }
|
|
||||||
|
|
||||||
public Guid AccountId { get; set; }
|
|
||||||
public string AccountName { get; set; }
|
|
||||||
|
|
||||||
public Guid UserId { get; set; }
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
public Guid ChannelId { get; set; }
|
|
||||||
public string ChannelName { get; set; }
|
|
||||||
public string ChannelProtoocl { get; set; }
|
|
||||||
|
|
||||||
public List<Guid> UAC_Matches { get; set; }
|
|
||||||
public List<string> BehavedOnBy { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,6 +23,7 @@ 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,8 +209,6 @@ 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(),
|
|
||||||
Protocol = PROTOCOL
|
Protocol = PROTOCOL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -291,7 +291,6 @@ 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,17 +179,6 @@ 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;
|
||||||
|
@ -11,5 +11,4 @@ public static class Shared
|
|||||||
public static string DBConnectionString { get; set; }
|
public static string DBConnectionString { get; set; }
|
||||||
public static HttpClient HttpClient { get; internal set; } = new HttpClient();
|
public static HttpClient HttpClient { get; internal set; } = new HttpClient();
|
||||||
public static bool SetupSlashCommands { get; set; }
|
public static bool SetupSlashCommands { get; set; }
|
||||||
public static Uri API_URL {get;set;}
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,5 @@
|
|||||||
"Trigger": "test",
|
"Trigger": "test",
|
||||||
"Uri": "http://localhost"
|
"Uri": "http://localhost"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"KafkaBootstrap":"http://localhost:9092",
|
|
||||||
"KafkaName":"vassago",
|
|
||||||
"API_URL": "http://localhost:5093/api"
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="bootstrap" Version="5.3.3" />
|
<PackageReference Include="bootstrap" Version="5.3.3" />
|
||||||
<PackageReference Include="discord.net" Version="3.10.0" />
|
<PackageReference Include="discord.net" Version="3.10.0" />
|
||||||
<PackageReference Include="greyn.franz" Version="2.1.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.20" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.20" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
Loading…
Reference in New Issue
Block a user