Compare commits

..

No commits in common. "e9ddcd237c61f2f64b563cb291c430e17b1f2f34" and "5bb64f764cacd90f02630470ca0ab68c47cf0ff0" have entirely different histories.

11 changed files with 51 additions and 103 deletions

View File

@ -45,7 +45,7 @@ public class QRify : Behavior
if(message.Channel.EffectivePermissions.MaxAttachmentBytes < (ulong)(new System.IO.FileInfo($"tmp/qr{todaysnumber}.png").Length))
await message.Channel.SendFile($"tmp/qr{todaysnumber}.png", null);
else
await message.Channel.SendMessage("resulting qr image 2 big 4 here");
message.Channel.SendMessage("resulting qr image 2 big 4 here");
File.Delete($"tmp/qr{todaysnumber}.svg");
File.Delete($"tmp/qr{todaysnumber}.png");
}

16
Configuration.cs Normal file
View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using vassago.TwitchInterface;
namespace vassago
{
public class Configuration
{
public string ExchangePairsLocation { get; set; }
public IEnumerable<string> DiscordTokens { get; set; }
public IEnumerable<TwitchConfig> TwitchConfigs { get; set; }
public string DBConnectionString { get; set; }
}
}

View File

@ -6,33 +6,34 @@ namespace vassago
internal class ConsoleService : IHostedService
{
Configuration config = new Configuration();
public ConsoleService(IConfiguration aspConfig)
{
Shared.DBConnectionString = aspConfig["DBConnectionString"];
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
config.DBConnectionString = aspConfig["DBConnectionString"];
config.ExchangePairsLocation = aspConfig["ExchangePairsLocation"];
config.DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
config.TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
}
IEnumerable<string> DiscordTokens { get; }
IEnumerable<TwitchConfig> TwitchConfigs { get; }
public async Task StartAsync(CancellationToken cancellationToken)
{
Shared.DBConnectionString = config.DBConnectionString;
var dbc = new ChattingContext();
dbc.Database.EnsureCreated();
if (DiscordTokens?.Any() ?? false)
foreach (var dt in DiscordTokens)
Conversion.Converter.Load(config.ExchangePairsLocation);
if (config.DiscordTokens?.Any() ?? false)
foreach (var dt in config.DiscordTokens)
{
var d = new DiscordInterface.DiscordInterface();
await d.Init(dt);
ProtocolInterfaces.ProtocolList.discords.Add(d);
}
if (TwitchConfigs?.Any() ?? false)
foreach (var tc in TwitchConfigs)
if (config.TwitchConfigs?.Any() ?? false)
foreach (var tc in config.TwitchConfigs)
{
var t = new TwitchInterface.TwitchInterface();
await t.Init(tc);

View File

@ -1,31 +0,0 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using vassago.Models;
namespace vassago.Controllers;
public class UsersController : Controller
{
private readonly ILogger<UsersController> _logger;
private readonly ChattingContext _db;
public UsersController(ILogger<UsersController> logger, ChattingContext db)
{
_logger = logger;
_db = db;
}
public async Task<IActionResult> Index(string searchString)
{
return _db.Users != null ?
View(await _db.Users.Include(u => u.Accounts).ToListAsync()) :
Problem("Entity set '_db.Users' is null.");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}

View File

@ -13,8 +13,6 @@ public class ChattingContext : DbContext
public DbSet<Account> Accounts { get; set; }
public DbSet<User> Users { get; set; }
public ChattingContext(DbContextOptions<ChattingContext> options) : base(options) { }
public ChattingContext() : base() { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql(Shared.DBConnectionString)
.EnableSensitiveDataLogging(true); //who the fuck is looking at log output but not allowed to see it? this should be on by default.

View File

@ -1,13 +1,8 @@
using Microsoft.EntityFrameworkCore;
using vassago.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
builder.Services.AddDbContext<ChattingContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("ChattingContext")));
var app = builder.Build();

View File

@ -117,7 +117,8 @@ public class DiscordInterface
private async Task SelfConnected()
{
var selfUser = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
var selfUser = UpsertAccount(client.CurrentUser);
selfUser.SeenInChannel = protocolAsChannel;
selfUser.DisplayName = client.CurrentUser.Username;
await _db.SaveChangesAsync();
@ -153,7 +154,8 @@ public class DiscordInterface
var guild = UpsertChannel(arg.Guild);
var defaultChannel = UpsertChannel(arg.Guild.DefaultChannel);
defaultChannel.ParentChannel = guild;
var u = UpsertAccount(arg, guild.Id);
var u = UpsertAccount(arg);
u.SeenInChannel = guild;
u.DisplayName = arg.DisplayName;
}
private async Task ButtonHandler(SocketMessageComponent component)
@ -228,7 +230,7 @@ public class DiscordInterface
m.ExternalId = dMessage.Id.ToString();
m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt;
m.Channel = UpsertChannel(dMessage.Channel);
m.Author = UpsertAccount(dMessage.Author, m.Channel.Id);
m.Author = UpsertAccount(dMessage.Author);
m.Author.SeenInChannel = m.Channel;
if(dMessage.Channel is IGuildChannel)
{
@ -297,10 +299,10 @@ public class DiscordInterface
c.SendFile = (f, t) => { throw new InvalidOperationException($"channel {channel.Name} is guild; send file"); };
return c;
}
internal Account UpsertAccount(IUser user, Guid inChannel)
internal Account UpsertAccount(IUser user)
{
var hadToAdd = false;
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel);
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.Protocol == PROTOCOL);
if (acc == null)
{
acc = new Account();

View File

@ -121,7 +121,8 @@ public class TwitchInterface
private async void Client_OnConnected(object sender, OnConnectedArgs e)
{
var selfUser = UpsertAccount(e.BotUsername, protocolAsChannel.Id);
var selfUser = UpsertAccount(e.BotUsername);
selfUser.SeenInChannel = protocolAsChannel;
await _db.SaveChangesAsync();
Behaver.Instance.Selves.Add(selfUser);
@ -139,10 +140,10 @@ public class TwitchInterface
Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}");
}
private Account UpsertAccount(string username, Guid inChannel)
private Account UpsertAccount(string username)
{
var hadToAdd = false;
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username && ui.SeenInChannel.Id == inChannel);
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username);
if (acc == null)
{
acc = new Account();
@ -220,7 +221,7 @@ public class TwitchInterface
m.Content = chatMessage.Message;
m.ExternalId = chatMessage.Id;
m.Channel = UpsertChannel(chatMessage.Channel);
m.Author = UpsertAccount(chatMessage.Username, m.Channel.Id);
m.Author = UpsertAccount(chatMessage.Username);
m.Author.SeenInChannel = m.Channel;
m.Reply = (t) => { return Task.Run(() => { client.SendReply(chatMessage.Channel, chatMessage.Id, t); }); };
@ -241,7 +242,7 @@ public class TwitchInterface
m.ExternalId = whisperMessage.MessageId;
m.Channel = UpsertDMChannel(whisperMessage.Username);
m.Channel.IsDM = true;
m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id);
m.Author = UpsertAccount(whisperMessage.Username);
m.Author.SeenInChannel = m.Channel;
m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });};

View File

@ -2,11 +2,11 @@
ViewData["Title"] = "Home Page";
}
<div>
<a href="Users">Users</a>
connected accounts?
</div>
<div>
<a href="Accounts">Accounts</a>
list of Users
</div>
<div>
<a href="Channels">Channels</a>
list of channels
</div>

View File

@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@ -1,40 +0,0 @@
@model IEnumerable<User>
@{
ViewData["Title"] = "Users";
}
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.PermissionTags)
</th>
<th>
number of associated accounts
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.PermissionTags)
</td>
<td>
@Html.DisplayFor(modelItem => item.Accounts.Count)x
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>