Compare commits

...

4 Commits

Author SHA1 Message Date
ee8cc96f71 known aliases for currency, from openexchangerates.org
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
fyi they have others, which they call "black market". notably in the black market: several cryptocurrencies. Notably *not* in the black market: bitcoin. Also notably not in the black market: several fantasies of the financial market. So if it's the legal argument, i don't get why bitcoin gets privilege. And obviously it's not the moral argument.

oh also a few jokes from myself.

see #28
2025-05-07 16:53:16 -04:00
e3c9a65f04 unit nicknames function
need to add them all to the conversion.json list

see #28
2025-05-07 15:23:00 -04:00
e0283e87f5 probably fix twitchsummon 2025-05-01 11:18:02 -04:00
0580a9d21f should deploy better
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
2025-04-29 14:50:11 -04:00
8 changed files with 1289 additions and 74 deletions

View File

@ -20,7 +20,7 @@ public class Behaver
var subtypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.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();
foreach (var subtype in subtypes)
@ -72,7 +72,7 @@ public class Behaver
public void MarkSelf(Account selfAccount)
{
if(SelfUser == null)
if (SelfUser == null)
{
SelfUser = selfAccount.IsUser;
}
@ -86,15 +86,25 @@ public class Behaver
public bool CollapseUsers(User primary, User secondary)
{
if(primary.Accounts == null)
if (primary.Accounts == null)
primary.Accounts = new List<Account>();
if(secondary.Accounts != null)
if (secondary.Accounts != null)
primary.Accounts.AddRange(secondary.Accounts);
foreach(var a in secondary.Accounts)
foreach (var a in secondary.Accounts)
{
a.IsUser = primary;
}
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.RememberUser(primary);
return true;

View File

@ -14,7 +14,7 @@ public class TwitchDismiss : Behavior
public override bool ShouldAct(Message message)
{
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 &&
(Regex.IsMatch(message.Content.ToLower(), "\\bbegone\\b") || Regex.IsMatch(message.Content.ToLower(), "\\bfuck off\\b")))
{

View File

@ -16,24 +16,36 @@ namespace vassago.Conversion
{
public static class Converter
{
public static string DebugInfo(){
var convertibles = knownConversions.Select(kc => kc.Item1).Union(knownConversions.Select(kc => kc.Item2)).Union(
knownAliases.Keys.SelectMany(k => k)).Distinct();
return $"{convertibles.Count()} convertibles; {string.Join(", ", convertibles)}";
}
private delegate decimal Convert1Way(decimal input);
private static string currencyPath;
private static ExchangePairs currencyConf = null;
private static DateTime lastUpdatedCurrency = DateTime.UnixEpoch;
private static List<Tuple<string, string, Convert1Way, Convert1Way>> knownConversions = new List<Tuple<string, string, Convert1Way, Convert1Way>>()
{
new Tuple<string, string, Convert1Way, Convert1Way>("℉", "°C", (f => {return(f- 32.0m) / 1.8m;}), (c => {return 1.8m*c + 32.0m;})),
};
private static List<Tuple<string, string, Convert1Way, Convert1Way>> knownConversions = new List<Tuple<string, string, Convert1Way, Convert1Way>>();
private static Dictionary<List<string>, string> knownAliases = new Dictionary<List<string>, string>(new List<KeyValuePair<List<string>, string>>());
public static string DebugInfo()
{
var convertibles = knownConversions.Select(kc => kc.Item1).Union(knownConversions.Select(kc => kc.Item2)).Union(
knownAliases.Keys.SelectMany(k => k)).Distinct();
return $"{convertibles.Count()} convertibles; {string.Join(", ", convertibles)}";
}
public static void Load(string currencyPath)
{
Converter.currencyPath = currencyPath;
loadStatic();
Task.Run(async () =>
{
while (true)
{
await Task.Delay(TimeSpan.FromHours(8));
loadCurrency();
}
});
}
private static void loadStatic()
{
knownConversions = new List<Tuple<string, string, Convert1Way, Convert1Way>>();
knownAliases = new Dictionary<List<string>, string>(new List<KeyValuePair<List<string>, string>>());
var convConf = JsonConvert.DeserializeObject<ConversionConfig>(File.ReadAllText("assets/conversion.json"));
foreach (var unit in convConf.Units)
{
@ -43,18 +55,12 @@ namespace vassago.Conversion
{
AddLinearPair(lp.item1, lp.item2, lp.factor);
}
Task.Run(async () => {
while(true)
{
loadCurrency();
await Task.Delay(TimeSpan.FromHours(8));
}
});
loadCurrency();
}
private static void loadCurrency()
{
Console.WriteLine("loading currency exchange data.");
if(currencyConf != null)
if (currencyConf != null)
{
knownConversions.RemoveAll(kc => kc.Item1 == currencyConf.Base);
}
@ -62,38 +68,41 @@ namespace vassago.Conversion
{
currencyConf = JsonConvert.DeserializeObject<ExchangePairs>(File.ReadAllText(currencyPath));
if(!knownAliases.ContainsValue(currencyConf.Base))
if (!knownAliases.ContainsValue(currencyConf.Base))
{
knownAliases.Add(new List<string>() { currencyConf.Base.ToLower() }, currencyConf.Base);
}
foreach (var rate in currencyConf.rates)
{
if(!knownAliases.ContainsValue(rate.Key))
if (!knownAliases.ContainsValue(rate.Key))
{
knownAliases.Add(new List<string>() { rate.Key.ToLower() }, rate.Key);
}
AddLinearPair(currencyConf.Base, rate.Key, rate.Value);
Console.WriteLine($"{rate.Key.ToLower()} alias of {rate.Key}");
}
}
}
public static string Convert(decimal numericTerm, string sourceunit, string destinationUnit)
{
var normalizedSourceUnit = NormalizeUnit(sourceunit);
if (string.IsNullOrWhiteSpace(normalizedSourceUnit))
var normalizationAttempt = NormalizeUnit(sourceunit);
if (normalizationAttempt.Item2 != null)
{
return $"parse failure: what's {sourceunit}?";
return $"problem with {sourceunit}: {normalizationAttempt.Item2}";
}
var normalizedDestUnit = NormalizeUnit(destinationUnit);
if (string.IsNullOrWhiteSpace(normalizedDestUnit))
var normalizedSourceUnit = normalizationAttempt.Item1;
normalizationAttempt = NormalizeUnit(destinationUnit);
if (normalizationAttempt.Item2 != null)
{
return $"parse failure: what's {destinationUnit}?";
return $"problem with {destinationUnit}: {normalizationAttempt.Item2}";
}
var normalizedDestUnit = normalizationAttempt.Item1;
if (normalizedSourceUnit == normalizedDestUnit)
{
return $"source and dest are the same, so... {numericTerm} {normalizedDestUnit}?";
}
var foundPath = exhaustiveBreadthFirst(normalizedDestUnit, new List<string>() { normalizedSourceUnit })?.ToList();
if (foundPath != null)
@ -118,7 +127,7 @@ namespace vassago.Conversion
}
else
{
if(String.Format("{0:G3}", accumulator).Contains("E-"))
if (String.Format("{0:G3}", accumulator).Contains("E-"))
{
return $"{accumulator} {normalizedDestUnit}";
}
@ -130,21 +139,34 @@ namespace vassago.Conversion
}
return "dimensional analysis failure - I know those units but can't find a path between them.";
}
private static string NormalizeUnit(string unit)
private static Tuple<string, string> NormalizeUnit(string unit)
{
if(string.IsNullOrWhiteSpace(unit))
return null;
if (string.IsNullOrWhiteSpace(unit))
return new(null, "no unit provided");
var normalizedUnit = unit.ToLower();
if (knownConversions.FirstOrDefault(c => c.Item1 == normalizedUnit || c.Item2 == normalizedUnit) != null)
{
return normalizedUnit;
return new(normalizedUnit, null);
}
//if "unit" isn't a canonical name...
if (!knownAliases.ContainsValue(normalizedUnit))
{
var key = knownAliases.Keys.FirstOrDefault(listkey => listkey.Contains(normalizedUnit));
if (key != null)
//then we look through aliases...
var keys = knownAliases.Keys.Where(listkey => listkey.Contains(normalizedUnit));
if (keys?.Count() > 1)
{
return knownAliases[key];
var sb = new StringBuilder();
sb.Append($"{normalizedUnit} could refer to any of");
foreach (var key in keys)
{
sb.Append($" {knownAliases[key]}");
}
return new(null, sb.ToString());
}
else if (keys.Count() == 1)
{
//for the canonical name.
return new(knownAliases[keys.First()], null);
}
}
if (normalizedUnit.EndsWith("es"))
@ -155,7 +177,7 @@ namespace vassago.Conversion
{
return NormalizeUnit(normalizedUnit.Substring(0, normalizedUnit.Length - 1));
}
return null;
return new(null, "couldn't find unit");
}
private static IEnumerable<string> exhaustiveBreadthFirst(string dest, IEnumerable<string> currentPath)
{
@ -170,9 +192,9 @@ namespace vassago.Conversion
{
if (conv.Item1 == last && currentPath.Contains(conv.Item2) == false && conv.Item3 != null)
{
var test = exhaustiveBreadthFirst(dest, currentPath.Append(conv.Item2));
if (test != null)
return test;
var test = exhaustiveBreadthFirst(dest, currentPath.Append(conv.Item2));
if (test != null)
return test;
}
if (conv.Item2 == last && currentPath.Contains(conv.Item1) == false && conv.Item4 != null)
{

3
Jenkinsfile vendored
View File

@ -59,7 +59,7 @@ pipeline {
{
sh """#!/bin/bash
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf temp_deploy & mkdir -p temp_deploy'
scp -i \"${PK}\" -r dist ${linuxServiceAccount_USR}@${env.targetHost}:temp_deploy
scp -i \"${PK}\" -r dist/ ${linuxServiceAccount_USR}@${env.targetHost}:temp_deploy
"""
}
}
@ -105,6 +105,7 @@ pipeline {
withCredentials([sshUserPrivateKey(credentialsId: env.linuxServiceAccountID, keyFileVariable: 'PK')])
{
sh """#!/bin/bash
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'cp dist oldgood-\$(mktemp -u XXXX)'
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv dist/appsettings.json appsettings.json'
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'rm -rf dist/ && shopt -s dotglob & mv temp_deploy/* dist/'
ssh -i \"${PK}\" -tt ${linuxServiceAccount_USR}@${targetHost} 'mv appsettings.json dist/appsettings.json'

View File

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

View File

@ -179,7 +179,16 @@ public static class Rememberer
dbAccessSemaphore.Release();
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();
db.Update(toRemember);

File diff suppressed because it is too large Load Diff

View File

@ -47,8 +47,8 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="wwwroot/**/*">
<None Include="wwwroot/**/*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</None>
</ItemGroup>
</Project>