forked from adam/discord-bot-shtik
Compare commits
4 Commits
059b2e657c
...
ee8cc96f71
Author | SHA1 | Date | |
---|---|---|---|
ee8cc96f71 | |||
e3c9a65f04 | |||
e0283e87f5 | |||
0580a9d21f |
10
Behaver.cs
10
Behaver.cs
@ -95,6 +95,16 @@ public class Behaver
|
||||
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;
|
||||
|
@ -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")))
|
||||
{
|
||||
|
@ -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,13 +55,7 @@ namespace vassago.Conversion
|
||||
{
|
||||
AddLinearPair(lp.item1, lp.item2, lp.factor);
|
||||
}
|
||||
Task.Run(async () => {
|
||||
while(true)
|
||||
{
|
||||
loadCurrency();
|
||||
await Task.Delay(TimeSpan.FromHours(8));
|
||||
}
|
||||
});
|
||||
}
|
||||
private static void loadCurrency()
|
||||
{
|
||||
@ -73,27 +79,30 @@ namespace vassago.Conversion
|
||||
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)
|
||||
@ -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;
|
||||
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)
|
||||
{
|
||||
|
3
Jenkinsfile
vendored
3
Jenkinsfile
vendored
@ -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'
|
||||
|
@ -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 = []
|
||||
@ -219,7 +220,7 @@ 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,7 +234,10 @@ 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
|
||||
{
|
||||
|
||||
|
@ -179,6 +179,15 @@ public static class Rememberer
|
||||
dbAccessSemaphore.Release();
|
||||
return toReturn;
|
||||
}
|
||||
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();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user