db in the right place; fix QR code math
This commit is contained in:
parent
c5f9ae2c6b
commit
b84e47344b
@ -10,14 +10,11 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
public class Behaver
|
public class Behaver
|
||||||
{
|
{
|
||||||
private ChattingContext _db;
|
|
||||||
private List<Account> SelfAccounts { get; set; } = new List<Account>();
|
private List<Account> SelfAccounts { get; set; } = new List<Account>();
|
||||||
private User SelfUser { get; set; }
|
private User SelfUser { get; set; }
|
||||||
public static List<Behavior> Behaviors { get; private set; } = new List<Behavior>();
|
public static List<Behavior> Behaviors { get; private set; } = new List<Behavior>();
|
||||||
internal Behaver()
|
internal Behaver()
|
||||||
{
|
{
|
||||||
_db = new ChattingContext();
|
|
||||||
|
|
||||||
var subtypes = AppDomain.CurrentDomain.GetAssemblies()
|
var subtypes = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.SelectMany(domainAssembly => domainAssembly.GetTypes())
|
.SelectMany(domainAssembly => domainAssembly.GetTypes())
|
||||||
.Where(type => type.IsSubclassOf(typeof(Behavior)) && !type.IsAbstract &&
|
.Where(type => type.IsSubclassOf(typeof(Behavior)) && !type.IsAbstract &&
|
||||||
@ -64,25 +61,27 @@ public class Behaver
|
|||||||
|
|
||||||
internal bool IsSelf(Guid AccountId)
|
internal bool IsSelf(Guid AccountId)
|
||||||
{
|
{
|
||||||
var acc = _db.Accounts.Find(AccountId);
|
var db = new ChattingContext();
|
||||||
|
var acc = db.Accounts.Find(AccountId);
|
||||||
|
|
||||||
return SelfAccounts.Any(acc => acc.Id == AccountId);
|
return SelfAccounts.Any(acc => acc.Id == AccountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MarkSelf(Account selfAccount)
|
public void MarkSelf(Account selfAccount)
|
||||||
{
|
{
|
||||||
|
var db = new ChattingContext();
|
||||||
if(SelfUser == null)
|
if(SelfUser == null)
|
||||||
{
|
{
|
||||||
SelfUser = selfAccount.IsUser;
|
SelfUser = selfAccount.IsUser;
|
||||||
}
|
}
|
||||||
else if (SelfUser != selfAccount.IsUser)
|
else if (SelfUser != selfAccount.IsUser)
|
||||||
{
|
{
|
||||||
CollapseUsers(SelfUser, selfAccount.IsUser);
|
CollapseUsers(SelfUser, selfAccount.IsUser, db);
|
||||||
}
|
}
|
||||||
SelfAccounts = _db.Accounts.Where(a => a.IsUser == SelfUser).ToList();
|
SelfAccounts = db.Accounts.Where(a => a.IsUser == SelfUser).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CollapseUsers(User primary, User secondary)
|
public bool CollapseUsers(User primary, User secondary, ChattingContext db)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{secondary.Id} is being consumed into {primary.Id}");
|
Console.WriteLine($"{secondary.Id} is being consumed into {primary.Id}");
|
||||||
primary.Accounts.AddRange(secondary.Accounts);
|
primary.Accounts.AddRange(secondary.Accounts);
|
||||||
@ -94,7 +93,7 @@ public class Behaver
|
|||||||
Console.WriteLine("accounts transferred");
|
Console.WriteLine("accounts transferred");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_db.SaveChanges();
|
db.SaveChangesAsync().Wait();
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@ -105,11 +104,11 @@ public class Behaver
|
|||||||
Console.WriteLine("saved");
|
Console.WriteLine("saved");
|
||||||
|
|
||||||
|
|
||||||
_db.Users.Remove(secondary);
|
db.Users.Remove(secondary);
|
||||||
Console.WriteLine("old account cleaned up");
|
Console.WriteLine("old account cleaned up");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_db.SaveChanges();
|
db.SaveChangesAsync().Wait();
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
@ -41,13 +41,11 @@ public class LinkClose : Behavior
|
|||||||
|
|
||||||
public override string Description => "the second half of LinkMe - this is confirmation that you are the other one";
|
public override string Description => "the second half of LinkMe - this is confirmation that you are the other one";
|
||||||
|
|
||||||
private ChattingContext _db;
|
|
||||||
private string _pw;
|
private string _pw;
|
||||||
private Account _primary;
|
private Account _primary;
|
||||||
|
|
||||||
public LinkClose(string pw, Account primary)
|
public LinkClose(string pw, Account primary)
|
||||||
{
|
{
|
||||||
_db = new ChattingContext();
|
|
||||||
_pw = pw;
|
_pw = pw;
|
||||||
_primary = primary;
|
_primary = primary;
|
||||||
}
|
}
|
||||||
@ -74,7 +72,7 @@ public class LinkClose : Behavior
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Behaver.Instance.CollapseUsers(_primary.IsUser, secondary))
|
if(Behaver.Instance.CollapseUsers(_primary.IsUser, secondary, new ChattingContext()))
|
||||||
{
|
{
|
||||||
await message.Channel.SendMessage("done :)");
|
await message.Channel.SendMessage("done :)");
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ public class QRify : Behavior
|
|||||||
File.WriteAllText($"tmp/qr{todaysnumber}.svg", qrCodeAsSvg);
|
File.WriteAllText($"tmp/qr{todaysnumber}.svg", qrCodeAsSvg);
|
||||||
if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png"))
|
if (ExternalProcess.GoPlz("convert", $"tmp/qr{todaysnumber}.svg tmp/qr{todaysnumber}.png"))
|
||||||
{
|
{
|
||||||
if(message.Channel.EffectivePermissions.MaxAttachmentBytes < (ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length))
|
if(message.Channel.EffectivePermissions.MaxAttachmentBytes >= (ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length))
|
||||||
await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null);
|
await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null);
|
||||||
else
|
else
|
||||||
await message.Channel.SendMessage("resulting qr image 2 big 4 here");
|
await message.Channel.SendMessage($"resulting qr image 2 big 4 here ({(ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length)} / {message.Channel.EffectivePermissions.MaxAttachmentBytes})");
|
||||||
File.Delete($"tmp/qr{todaysnumber}.svg");
|
File.Delete($"tmp/qr{todaysnumber}.svg");
|
||||||
File.Delete($"tmp/qr{todaysnumber}.png");
|
File.Delete($"tmp/qr{todaysnumber}.png");
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ namespace vassago
|
|||||||
await t.Init(tc);
|
await t.Init(tc);
|
||||||
ProtocolInterfaces.ProtocolList.twitchs.Add(t);
|
ProtocolInterfaces.ProtocolList.twitchs.Add(t);
|
||||||
}
|
}
|
||||||
|
Console.WriteLine("survived initting");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
@ -7,7 +7,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
||||||
builder.Services.AddDbContext<ChattingContext>(options =>
|
builder.Services.AddDbContext<ChattingContext>(options =>
|
||||||
options.UseNpgsql(builder.Configuration.GetConnectionString("ChattingContext") ),ServiceLifetime.Transient);
|
options.UseNpgsql(builder.Configuration.GetConnectionString("ChattingContext") ));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -115,10 +115,10 @@ public class TwitchInterface
|
|||||||
var m = UpsertMessage(e.WhisperMessage);
|
var m = UpsertMessage(e.WhisperMessage);
|
||||||
m.Channel.ChannelType = vassago.Models.Enumerations.ChannelType.DM;
|
m.Channel.ChannelType = vassago.Models.Enumerations.ChannelType.DM;
|
||||||
m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b");
|
m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b");
|
||||||
_db.SaveChanges();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
await Behaver.Instance.ActOn(m);
|
await Behaver.Instance.ActOn(m);
|
||||||
_db.SaveChanges();
|
await _db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e)
|
private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e)
|
||||||
@ -134,10 +134,10 @@ public class TwitchInterface
|
|||||||
var m = UpsertMessage(e.ChatMessage);
|
var m = UpsertMessage(e.ChatMessage);
|
||||||
m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") ||
|
m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") ||
|
||||||
e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername;
|
e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername;
|
||||||
_db.SaveChanges();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
await Behaver.Instance.ActOn(m);
|
await Behaver.Instance.ActOn(m);
|
||||||
_db.SaveChanges();
|
await _db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Client_OnConnected(object sender, OnConnectedArgs e)
|
private async void Client_OnConnected(object sender, OnConnectedArgs e)
|
||||||
|
Reference in New Issue
Block a user