forked from adam/discord-bot-shtik
backgroundservice instead of IHostedService - now I can *see* my g.d. errors!
This commit is contained in:
parent
0506d331c5
commit
a55e7a74ab
@ -8,7 +8,7 @@ namespace vassago
|
|||||||
using vassago.ProtocolInterfaces.DiscordInterface;
|
using vassago.ProtocolInterfaces.DiscordInterface;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
internal class ConsoleService : IHostedService
|
internal class ConsoleService : BackgroundService
|
||||||
{
|
{
|
||||||
public ConsoleService(IConfiguration aspConfig)
|
public ConsoleService(IConfiguration aspConfig)
|
||||||
{
|
{
|
||||||
@ -25,7 +25,7 @@ namespace vassago
|
|||||||
IEnumerable<string> DiscordTokens { get; }
|
IEnumerable<string> DiscordTokens { get; }
|
||||||
IEnumerable<TwitchConfig> TwitchConfigs { get; }
|
IEnumerable<TwitchConfig> TwitchConfigs { get; }
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var initTasks = new List<Task>();
|
var initTasks = new List<Task>();
|
||||||
var dbc = new ChattingContext();
|
var dbc = new ChattingContext();
|
||||||
@ -50,9 +50,5 @@ namespace vassago
|
|||||||
Task.WaitAll(initTasks.ToArray(), cancellationToken);
|
Task.WaitAll(initTasks.ToArray(), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,6 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (!app.Environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
app.UseExceptionHandler("/Home/Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
@ -46,7 +40,7 @@ app.UseSwaggerUI(c =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
//app.UseExceptionHandler();
|
//app.UseExceptionHandler();
|
||||||
app.UseStatusCodePages();
|
//app.UseStatusCodePages();
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
52
WebInterface/Controllers/api/AccountsController.cs
Normal file
52
WebInterface/Controllers/api/AccountsController.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using vassago.Models;
|
||||||
|
using vassago.ProtocolInterfaces.DiscordInterface;
|
||||||
|
|
||||||
|
namespace vassago.Controllers.api;
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class AccountsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<AccountsController> _logger;
|
||||||
|
|
||||||
|
public AccountsController(ILogger<AccountsController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
//microsoft: "you can't have multiple [FromBody]. The reason for this rule is some bullshti about storage buffers."
|
||||||
|
//cool story, bro. nobody gives a fuck, look at the boilerplate you've necessitated.
|
||||||
|
public class extraSpecialObjectReadGlorifiedTupleFor_UnlinkUser
|
||||||
|
{
|
||||||
|
public Guid acc_guid;
|
||||||
|
}
|
||||||
|
[HttpPatch]
|
||||||
|
[Route("UnlinkUser")]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public IActionResult UnlinkUser([FromBody] extraSpecialObjectReadGlorifiedTupleFor_UnlinkUser req)
|
||||||
|
{
|
||||||
|
var acc_guid = req.acc_guid;
|
||||||
|
var accFromDb = Rememberer.SearchAccount(acc => acc.Id == acc_guid);
|
||||||
|
if (accFromDb == null)
|
||||||
|
{
|
||||||
|
var err = $"attempt to unlink user for acc {acc_guid}, not found";
|
||||||
|
_logger.LogError(err);
|
||||||
|
return NotFound(err);
|
||||||
|
}
|
||||||
|
var userFromDb = Rememberer.SearchUser(c => c.Id == accFromDb.IsUser.Id);
|
||||||
|
if (userFromDb == null)
|
||||||
|
{
|
||||||
|
var err = $"attempt to unlink user for {acc_guid}, doesn't have a user";
|
||||||
|
_logger.LogError(err);
|
||||||
|
return NotFound(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
accFromDb.IsUser = null;
|
||||||
|
|
||||||
|
Rememberer.RememberAccount(accFromDb);
|
||||||
|
return Ok(accFromDb);
|
||||||
|
}
|
||||||
|
}
|
@ -8,19 +8,23 @@
|
|||||||
<a href="/">home</a>/@Html.Raw(ViewData["breadcrumbs"])
|
<a href="/">home</a>/@Html.Raw(ViewData["breadcrumbs"])
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<td>@Model.Id</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">belongs to user</th>
|
<th scope="row">belongs to user</th>
|
||||||
<td>@Model.IsUser.DisplayName</td>
|
<td>@Model.IsUser.DisplayName</td>
|
||||||
<td><button alt="to do" disabled>separate</button></2td>
|
<td><button onclick="unlinkAccountUser(() => { window.location.reload(); })">separate</button></2td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Seen in channel</th>
|
<th scope="row">Seen in channel</th>
|
||||||
<td class="account @Model.SeenInChannel.Protocol"><div class="protocol-icon"> </div>@Model.SeenInChannel.LineageSummary<a href="/Channels/Details/@Model.SeenInChannel.Id">@Model.SeenInChannel.DisplayName</a></td>
|
<td class="account @Model.SeenInChannel.Protocol"><div class="protocol-icon"> </div>@Model.SeenInChannel.LineageSummary<a href="/Channels/Details/@Model.SeenInChannel.Id">@Model.SeenInChannel.DisplayName</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Permission Tags</th>
|
<th scope="row">UACs tied to account</th>
|
||||||
<td>
|
<td>
|
||||||
<div id="tagsTree"></div>
|
<div id="uacsTree"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -44,10 +48,10 @@
|
|||||||
return userNow;
|
return userNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTagsTree() {
|
function getUacsTree() {
|
||||||
@{
|
@{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("[{text: \"permission tags\", \"expanded\":true, nodes: [");
|
sb.Append("[{text: \"UACs\", \"expanded\":true, nodes: [");
|
||||||
var first = true;
|
var first = true;
|
||||||
for (int i = 0; i < 1; i++)
|
for (int i = 0; i < 1; i++)
|
||||||
{
|
{
|
||||||
@ -62,7 +66,7 @@
|
|||||||
var tree = @Html.Raw(sb.ToString());
|
var tree = @Html.Raw(sb.ToString());
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
$('#tagsTree').bstreeview({ data: getTagsTree() });
|
$('#uacsTree').bstreeview({ data: getUacsTree() });
|
||||||
document.querySelectorAll("input[type=checkbox]").forEach(node => { node.onchange = () => { patchModel(jsonifyUser(), '/api/Users/') } });
|
//document.querySelectorAll("input[type=checkbox]").forEach(node => { node.onchange = () => { patchModel(jsonifyUser(), '/api/Users/') } });
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ function deleteModel(model, deprecated_apiUrl)
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function linkUAC_Channel(channel_guid, callback)
|
function linkUAC_Channel(channel_guid, callback)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -246,3 +246,31 @@ function unlinkUAC_Channel(user_guid, callback)
|
|||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//give me account, we'll tear it off from user.
|
||||||
|
function unlinkAccountUser(callback)
|
||||||
|
{
|
||||||
|
var components = window.location.pathname.split('/');
|
||||||
|
var id=components[3];
|
||||||
|
let model={"acc_guid": id};
|
||||||
|
fetch(apiUrl + "Accounts/UnlinkUser/", {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(model),
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not "ok". which is not ok.');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(returnedSuccessdata => {
|
||||||
|
// perhaps a success callback
|
||||||
|
console.log('returnedSuccessdata:', returnedSuccessdata);
|
||||||
|
if(callback !== null) { callback(); }
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user