forked from adam/discord-bot-shtik
Compare commits
No commits in common. "e9ddcd237c61f2f64b563cb291c430e17b1f2f34" and "5bb64f764cacd90f02630470ca0ab68c47cf0ff0" have entirely different histories.
e9ddcd237c
...
5bb64f764c
@ -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
|
||||||
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}.svg");
|
||||||
File.Delete($"tmp/qr{todaysnumber}.png");
|
File.Delete($"tmp/qr{todaysnumber}.png");
|
||||||
}
|
}
|
||||||
|
16
Configuration.cs
Normal file
16
Configuration.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -6,33 +6,34 @@ namespace vassago
|
|||||||
|
|
||||||
internal class ConsoleService : IHostedService
|
internal class ConsoleService : IHostedService
|
||||||
{
|
{
|
||||||
|
Configuration config = new Configuration();
|
||||||
|
|
||||||
public ConsoleService(IConfiguration aspConfig)
|
public ConsoleService(IConfiguration aspConfig)
|
||||||
{
|
{
|
||||||
Shared.DBConnectionString = aspConfig["DBConnectionString"];
|
config.DBConnectionString = aspConfig["DBConnectionString"];
|
||||||
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
config.ExchangePairsLocation = aspConfig["ExchangePairsLocation"];
|
||||||
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
config.DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
||||||
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
|
config.TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
if (DiscordTokens?.Any() ?? false)
|
Conversion.Converter.Load(config.ExchangePairsLocation);
|
||||||
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 (TwitchConfigs?.Any() ?? false)
|
if (config.TwitchConfigs?.Any() ?? false)
|
||||||
foreach (var tc in TwitchConfigs)
|
foreach (var tc in config.TwitchConfigs)
|
||||||
{
|
{
|
||||||
var t = new TwitchInterface.TwitchInterface();
|
var t = new TwitchInterface.TwitchInterface();
|
||||||
await t.Init(tc);
|
await t.Init(tc);
|
||||||
|
@ -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 });
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,8 +13,6 @@ 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,13 +1,8 @@
|
|||||||
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,7 +117,8 @@ public class DiscordInterface
|
|||||||
|
|
||||||
private async Task SelfConnected()
|
private async Task SelfConnected()
|
||||||
{
|
{
|
||||||
var selfUser = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
|
var selfUser = UpsertAccount(client.CurrentUser);
|
||||||
|
selfUser.SeenInChannel = protocolAsChannel;
|
||||||
selfUser.DisplayName = client.CurrentUser.Username;
|
selfUser.DisplayName = client.CurrentUser.Username;
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
@ -153,7 +154,8 @@ 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, guild.Id);
|
var u = UpsertAccount(arg);
|
||||||
|
u.SeenInChannel = guild;
|
||||||
u.DisplayName = arg.DisplayName;
|
u.DisplayName = arg.DisplayName;
|
||||||
}
|
}
|
||||||
private async Task ButtonHandler(SocketMessageComponent component)
|
private async Task ButtonHandler(SocketMessageComponent component)
|
||||||
@ -228,7 +230,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.Channel.Id);
|
m.Author = UpsertAccount(dMessage.Author);
|
||||||
m.Author.SeenInChannel = m.Channel;
|
m.Author.SeenInChannel = m.Channel;
|
||||||
if(dMessage.Channel is IGuildChannel)
|
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"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"channel {channel.Name} is guild; send file"); };
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
internal Account UpsertAccount(IUser user, Guid inChannel)
|
internal Account UpsertAccount(IUser user)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
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)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
|
@ -121,7 +121,8 @@ 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, protocolAsChannel.Id);
|
var selfUser = UpsertAccount(e.BotUsername);
|
||||||
|
selfUser.SeenInChannel = protocolAsChannel;
|
||||||
|
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
Behaver.Instance.Selves.Add(selfUser);
|
Behaver.Instance.Selves.Add(selfUser);
|
||||||
@ -139,10 +140,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, Guid inChannel)
|
private Account UpsertAccount(string username)
|
||||||
{
|
{
|
||||||
var hadToAdd = false;
|
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)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
@ -220,7 +221,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.Channel.Id);
|
m.Author = UpsertAccount(chatMessage.Username);
|
||||||
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); }); };
|
||||||
@ -241,7 +242,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.Channel.Id);
|
m.Author = UpsertAccount(whisperMessage.Username);
|
||||||
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>
|
||||||
<a href="Users">Users</a>
|
connected accounts?
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="Accounts">Accounts</a>
|
list of Users
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<a href="Channels">Channels</a>
|
list of channels
|
||||||
</div>
|
</div>
|
||||||
|
6
Views/Home/Privacy.cshtml
Normal file
6
Views/Home/Privacy.cshtml
Normal 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>
|
@ -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>
|
|
Loading…
Reference in New Issue
Block a user