forked from adam/discord-bot-shtik
Compare commits
2 Commits
5bb64f764c
...
e9ddcd237c
Author | SHA1 | Date | |
---|---|---|---|
e9ddcd237c | |||
4a60e53798 |
@ -45,7 +45,7 @@ public class QRify : Behavior
|
|||||||
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
|
||||||
message.Channel.SendMessage("resulting qr image 2 big 4 here");
|
await message.Channel.SendMessage("resulting qr image 2 big 4 here");
|
||||||
File.Delete($"tmp/qr{todaysnumber}.svg");
|
File.Delete($"tmp/qr{todaysnumber}.svg");
|
||||||
File.Delete($"tmp/qr{todaysnumber}.png");
|
File.Delete($"tmp/qr{todaysnumber}.png");
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,34 +6,33 @@ namespace vassago
|
|||||||
|
|
||||||
internal class ConsoleService : IHostedService
|
internal class ConsoleService : IHostedService
|
||||||
{
|
{
|
||||||
Configuration config = new Configuration();
|
|
||||||
|
|
||||||
public ConsoleService(IConfiguration aspConfig)
|
public ConsoleService(IConfiguration aspConfig)
|
||||||
{
|
{
|
||||||
config.DBConnectionString = aspConfig["DBConnectionString"];
|
Shared.DBConnectionString = aspConfig["DBConnectionString"];
|
||||||
config.ExchangePairsLocation = aspConfig["ExchangePairsLocation"];
|
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
||||||
config.DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
||||||
config.TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerable<string> DiscordTokens { get; }
|
||||||
|
IEnumerable<TwitchConfig> TwitchConfigs { get; }
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Shared.DBConnectionString = config.DBConnectionString;
|
|
||||||
var dbc = new ChattingContext();
|
var dbc = new ChattingContext();
|
||||||
dbc.Database.EnsureCreated();
|
dbc.Database.EnsureCreated();
|
||||||
|
|
||||||
Conversion.Converter.Load(config.ExchangePairsLocation);
|
if (DiscordTokens?.Any() ?? false)
|
||||||
|
foreach (var dt in DiscordTokens)
|
||||||
if (config.DiscordTokens?.Any() ?? false)
|
|
||||||
foreach (var dt in config.DiscordTokens)
|
|
||||||
{
|
{
|
||||||
var d = new DiscordInterface.DiscordInterface();
|
var d = new DiscordInterface.DiscordInterface();
|
||||||
await d.Init(dt);
|
await d.Init(dt);
|
||||||
ProtocolInterfaces.ProtocolList.discords.Add(d);
|
ProtocolInterfaces.ProtocolList.discords.Add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.TwitchConfigs?.Any() ?? false)
|
if (TwitchConfigs?.Any() ?? false)
|
||||||
foreach (var tc in config.TwitchConfigs)
|
foreach (var tc in TwitchConfigs)
|
||||||
{
|
{
|
||||||
var t = new TwitchInterface.TwitchInterface();
|
var t = new TwitchInterface.TwitchInterface();
|
||||||
await t.Init(tc);
|
await t.Init(tc);
|
||||||
|
31
Controllers/UsersController.cs
Normal file
31
Controllers/UsersController.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,8 @@ public class ChattingContext : DbContext
|
|||||||
public DbSet<Account> Accounts { get; set; }
|
public DbSet<Account> Accounts { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public ChattingContext(DbContextOptions<ChattingContext> options) : base(options) { }
|
||||||
|
public ChattingContext() : base() { }
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
=> optionsBuilder.UseNpgsql(Shared.DBConnectionString)
|
=> 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.
|
.EnableSensitiveDataLogging(true); //who the fuck is looking at log output but not allowed to see it? this should be on by default.
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using vassago.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
||||||
|
builder.Services.AddDbContext<ChattingContext>(options =>
|
||||||
|
options.UseNpgsql(builder.Configuration.GetConnectionString("ChattingContext")));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
@ -117,8 +117,7 @@ public class DiscordInterface
|
|||||||
|
|
||||||
private async Task SelfConnected()
|
private async Task SelfConnected()
|
||||||
{
|
{
|
||||||
var selfUser = UpsertAccount(client.CurrentUser);
|
var selfUser = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
|
||||||
selfUser.SeenInChannel = protocolAsChannel;
|
|
||||||
selfUser.DisplayName = client.CurrentUser.Username;
|
selfUser.DisplayName = client.CurrentUser.Username;
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
@ -154,8 +153,7 @@ public class DiscordInterface
|
|||||||
var guild = UpsertChannel(arg.Guild);
|
var guild = UpsertChannel(arg.Guild);
|
||||||
var defaultChannel = UpsertChannel(arg.Guild.DefaultChannel);
|
var defaultChannel = UpsertChannel(arg.Guild.DefaultChannel);
|
||||||
defaultChannel.ParentChannel = guild;
|
defaultChannel.ParentChannel = guild;
|
||||||
var u = UpsertAccount(arg);
|
var u = UpsertAccount(arg, guild.Id);
|
||||||
u.SeenInChannel = guild;
|
|
||||||
u.DisplayName = arg.DisplayName;
|
u.DisplayName = arg.DisplayName;
|
||||||
}
|
}
|
||||||
private async Task ButtonHandler(SocketMessageComponent component)
|
private async Task ButtonHandler(SocketMessageComponent component)
|
||||||
@ -230,7 +228,7 @@ public class DiscordInterface
|
|||||||
m.ExternalId = dMessage.Id.ToString();
|
m.ExternalId = dMessage.Id.ToString();
|
||||||
m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt;
|
m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt;
|
||||||
m.Channel = UpsertChannel(dMessage.Channel);
|
m.Channel = UpsertChannel(dMessage.Channel);
|
||||||
m.Author = UpsertAccount(dMessage.Author);
|
m.Author = UpsertAccount(dMessage.Author, m.Channel.Id);
|
||||||
m.Author.SeenInChannel = m.Channel;
|
m.Author.SeenInChannel = m.Channel;
|
||||||
if(dMessage.Channel is IGuildChannel)
|
if(dMessage.Channel is IGuildChannel)
|
||||||
{
|
{
|
||||||
@ -299,10 +297,10 @@ public class DiscordInterface
|
|||||||
c.SendFile = (f, t) => { throw new InvalidOperationException($"channel {channel.Name} is guild; send file"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"channel {channel.Name} is guild; send file"); };
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
internal Account UpsertAccount(IUser user)
|
internal Account UpsertAccount(IUser user, Guid inChannel)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
var hadToAdd = false;
|
||||||
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.Protocol == PROTOCOL);
|
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel);
|
||||||
if (acc == null)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
|
@ -121,8 +121,7 @@ public class TwitchInterface
|
|||||||
|
|
||||||
private async void Client_OnConnected(object sender, OnConnectedArgs e)
|
private async void Client_OnConnected(object sender, OnConnectedArgs e)
|
||||||
{
|
{
|
||||||
var selfUser = UpsertAccount(e.BotUsername);
|
var selfUser = UpsertAccount(e.BotUsername, protocolAsChannel.Id);
|
||||||
selfUser.SeenInChannel = protocolAsChannel;
|
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
Behaver.Instance.Selves.Add(selfUser);
|
Behaver.Instance.Selves.Add(selfUser);
|
||||||
@ -140,10 +139,10 @@ public class TwitchInterface
|
|||||||
Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}");
|
Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account UpsertAccount(string username)
|
private Account UpsertAccount(string username, Guid inChannel)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
var hadToAdd = false;
|
||||||
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username);
|
var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username && ui.SeenInChannel.Id == inChannel);
|
||||||
if (acc == null)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
@ -221,7 +220,7 @@ public class TwitchInterface
|
|||||||
m.Content = chatMessage.Message;
|
m.Content = chatMessage.Message;
|
||||||
m.ExternalId = chatMessage.Id;
|
m.ExternalId = chatMessage.Id;
|
||||||
m.Channel = UpsertChannel(chatMessage.Channel);
|
m.Channel = UpsertChannel(chatMessage.Channel);
|
||||||
m.Author = UpsertAccount(chatMessage.Username);
|
m.Author = UpsertAccount(chatMessage.Username, m.Channel.Id);
|
||||||
m.Author.SeenInChannel = m.Channel;
|
m.Author.SeenInChannel = m.Channel;
|
||||||
|
|
||||||
m.Reply = (t) => { return Task.Run(() => { client.SendReply(chatMessage.Channel, chatMessage.Id, t); }); };
|
m.Reply = (t) => { return Task.Run(() => { client.SendReply(chatMessage.Channel, chatMessage.Id, t); }); };
|
||||||
@ -242,7 +241,7 @@ public class TwitchInterface
|
|||||||
m.ExternalId = whisperMessage.MessageId;
|
m.ExternalId = whisperMessage.MessageId;
|
||||||
m.Channel = UpsertDMChannel(whisperMessage.Username);
|
m.Channel = UpsertDMChannel(whisperMessage.Username);
|
||||||
m.Channel.IsDM = true;
|
m.Channel.IsDM = true;
|
||||||
m.Author = UpsertAccount(whisperMessage.Username);
|
m.Author = UpsertAccount(whisperMessage.Username, m.Channel.Id);
|
||||||
m.Author.SeenInChannel = m.Channel;
|
m.Author.SeenInChannel = m.Channel;
|
||||||
|
|
||||||
m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });};
|
m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });};
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
ViewData["Title"] = "Home Page";
|
ViewData["Title"] = "Home Page";
|
||||||
}
|
}
|
||||||
<div>
|
<div>
|
||||||
connected accounts?
|
<a href="Users">Users</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
list of Users
|
<a href="Accounts">Accounts</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
list of channels
|
<a href="Channels">Channels</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
@{
|
|
||||||
ViewData["Title"] = "Privacy Policy";
|
|
||||||
}
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
|
|
||||||
<p>Use this page to detail your site's privacy policy.</p>
|
|
40
Views/Users/Index.cshtml
Normal file
40
Views/Users/Index.cshtml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
@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>
|
Loading…
Reference in New Issue
Block a user