forked from adam/discord-bot-shtik
frontend progress. I am *almost* returning to monke.... but my datatype uses strings to serialize some objects in order to cooperate with entity framework.
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
Some checks failed
gitea.arg.rip/vassago/pipeline/head There was a failure building this commit
how hard do you want to not use javascript.. is knockout.js worse than a viewmodel?
This commit is contained in:
parent
a337ca8a5f
commit
56c71ee533
@ -37,10 +37,19 @@ namespace vassago
|
||||
foreach (var dt in DiscordTokens)
|
||||
{
|
||||
var d = new DiscordInterface();
|
||||
initTasks.Add(d.Init(dt));
|
||||
initTasks.Add(Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
d.Init(dt);
|
||||
Shared.ProtocolList.Add(d);
|
||||
}
|
||||
|
||||
catch (Exception e){
|
||||
Console.Error.WriteLine($"couldn't initialize discord interface with token {dt}");
|
||||
Console.Error.WriteLine(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (TwitchConfigs?.Any() ?? false)
|
||||
foreach (var tc in TwitchConfigs)
|
||||
{
|
||||
@ -50,6 +59,7 @@ namespace vassago
|
||||
}
|
||||
|
||||
Task.WaitAll(initTasks.ToArray(), cancellationToken);
|
||||
Console.WriteLine("init tasks are done");
|
||||
}
|
||||
private void dbConfig(ref vassago.Models.Configuration confEntity)
|
||||
{
|
||||
|
@ -33,6 +33,8 @@ public class DiscordInterface : ProtocolInterface
|
||||
public async Task Init(string config)
|
||||
{
|
||||
var token = config;
|
||||
Console.WriteLine($"going to validate token {token}");
|
||||
Discord.TokenUtils.ValidateToken(TokenType.Bot, token);//throws an exception if invalid
|
||||
await SetupDiscordChannel();
|
||||
client = new DiscordSocketClient(new DiscordSocketConfig() { GatewayIntents = GatewayIntents.All });
|
||||
|
||||
@ -41,12 +43,18 @@ public class DiscordInterface : ProtocolInterface
|
||||
Console.WriteLine(msg.ToString());
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
client.Connected += () => Task.Run(SelfConnected);
|
||||
client.Ready += () => Task.Run(ClientReady);
|
||||
client.Connected += this.SelfConnected;
|
||||
client.Disconnected += this.ClientDisconnected;
|
||||
client.Ready += this.ClientReady;
|
||||
|
||||
await client.LoginAsync(TokenType.Bot, token);
|
||||
await client.StartAsync();
|
||||
}
|
||||
private async Task ClientDisconnected(Exception e)
|
||||
{
|
||||
Console.WriteLine("client disconnected!");
|
||||
Console.WriteLine(e?.Message);
|
||||
}
|
||||
|
||||
private async Task SetupDiscordChannel()
|
||||
{
|
||||
|
@ -354,4 +354,11 @@ public class Rememberer
|
||||
dbAccessSemaphore.Release();
|
||||
return toReturn;
|
||||
}
|
||||
public void RememberConfiguration(Configuration conf)
|
||||
{
|
||||
dbAccessSemaphore.Wait();
|
||||
db.Update(conf);
|
||||
db.SaveChanges();
|
||||
dbAccessSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,15 @@ public class ConfigurationController() : Controller
|
||||
{
|
||||
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult AddDiscord(string newToken)
|
||||
{
|
||||
Console.WriteLine($"remembering discord, {newToken}");
|
||||
var conf = r.Configuration();
|
||||
conf.DiscordTokens ??=[];
|
||||
conf.DiscordTokens.Add(newToken);
|
||||
r.RememberConfiguration(conf);
|
||||
return RedirectToAction("Index", "Configuration");
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
@model vassago.Models.Configuration
|
||||
@using Newtonsoft.Json;
|
||||
@using vassago.Behavior;
|
||||
@{
|
||||
}
|
||||
|
||||
<a href="/">home</a>/configuration
|
||||
<form action="@Url.Action("submit", "Configuration")" method="post">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th colspa="2">Discord</th>
|
||||
<th colspan="2">Discord (@(Model?.DiscordTokens?.Count ?? 0) accounts)</th>
|
||||
</tr>
|
||||
@{
|
||||
if(Model.DiscordTokens != null) for(var i = 0; i < Model.DiscordTokens.Count; i++)
|
||||
{
|
||||
Html.Raw("<tr>");
|
||||
Html.Raw($"<th><label for=\"DiscordTokens[{i}]\"></label></th>");
|
||||
Html.Raw($"<td><input type=\"text\" class=\"form-control\" id=\"DiscordTokens[{i}]\" value=\"{Model.DiscordTokens[i]}\"/></td>");
|
||||
Html.Raw("</tr>");
|
||||
<tr>
|
||||
<th><label for="DiscordTokens[@i]"></label></th>
|
||||
<td>
|
||||
<input type="text" class="form-control" name="DiscordTokens[@i]" value="@Model.DiscordTokens[i]"/>
|
||||
<button type="button" onclick="() => {removeDiscordTarget = @i; removeDiscord.showModal();}" class="btn btn-danger">del</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
<tr>
|
||||
@ -30,18 +32,22 @@
|
||||
<td><input type="checkbox" class="form-check-input position-static" id="SetupDiscordSlashCommands" checked="@Model.SetupDiscordSlashCommands"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="2">Twitch</th>
|
||||
<th colspan="2">Twitch (@(Model?.TwitchConfigs?.Count ?? 0) accounts)</th>
|
||||
</tr>
|
||||
@{
|
||||
if(Model.TwitchConfigs != null) for(var i = 0; i < Model.TwitchConfigs.Count; i++)
|
||||
{
|
||||
Html.Raw("<tr>");
|
||||
Html.Raw($"<th><label for=\"TwitchConfigs[{i}]\"></label></th>");
|
||||
Html.Raw("<td>");
|
||||
Html.Raw("<input type=\"text\" class=\"form-control\" id=\"TwitchConfigs[{i}].username\" value=\"{Model.TwitchConfigs[i].username}\"/>");
|
||||
Html.Raw("<input type=\"text\" class=\"form-control\" id=\"TwitchConfigs[{i}].oauth\" value=\"{Model.TwitchConfigs[i].oauth}\"/>");
|
||||
Html.Raw("</td>");
|
||||
Html.Raw("</tr>");
|
||||
var tc = JsonConvert.DeserializeObject<TwitchConfig>(Model.TwitchConfigs[i]);
|
||||
|
||||
<tr>
|
||||
<th><label for="TwitchConfigs[@i]"></label></th>
|
||||
<td>
|
||||
<input type="hidden" name="TwitchConfigs[@i]" value="@Model.TwitchConfigs[i]" />
|
||||
<input type="text" class="form-control" value="@tc.username"/><!--//TODO: save me, knockout.js!-->
|
||||
<input type="text" class="form-control" value="@tc.oauth"/>
|
||||
<button type="button" onclick="() => {removeTwitchTarget = @i; removeTwitch.showModal();}" class="btn btn-danger">del</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
<tr>
|
||||
@ -109,6 +115,14 @@
|
||||
<button class="btn btn-success" type="submit">save</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<dialog id="removeDiscord">
|
||||
<form action="@Url.Action("RemoveDiscord", "Configuration")" method="delete">
|
||||
Are you sure?
|
||||
<input type="hidden" name="id" id="removeDiscordTarget" />
|
||||
<button class="btn btn-secondary" type="button" onclick="removeDiscord.close()">cancel</button>
|
||||
<button class="btn btn-danger" type="submit">delete</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<dialog id="addTwitch">
|
||||
<form action="@Url.Action("AddTwitch", "Configuration")" method="post">
|
||||
<input type="text" class="form-control" name="newUsername" />
|
||||
@ -117,6 +131,14 @@
|
||||
<button class="btn btn-success" type="submit">save</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<dialog id="removeTwitch">
|
||||
<form action="@Url.Action("RemoveTwitch", "Configuration")" method="delete">
|
||||
Are you sure?
|
||||
<input type="hidden" name="id" id="removeTwitchTarget" />
|
||||
<button class="btn btn-secondary" type="button" onclick="removeTwitch.close()">cancel</button>
|
||||
<button class="btn btn-danger" type="submit">delete</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<dialog id="addWebhook">
|
||||
<form action="@Url.Action("AddWebhook", "Configuration")" method="post">
|
||||
<input type="text" class="form-control" name="newTrigger" />
|
||||
@ -124,3 +146,11 @@
|
||||
<button class="btn btn-success" type="submit">save</button>
|
||||
</form>
|
||||
</dialog>
|
||||
<dialog id="removeWebhook">
|
||||
<form action="@Url.Action("RemoveWebhook", "Configuration")" method="delete">
|
||||
Are you sure?
|
||||
<input type="hidden" name="id" id="removeWebhookTarget" />
|
||||
<button class="btn btn-secondary" type="button" onclick="removeWebhook.close()">cancel</button>
|
||||
<button class="btn btn-danger" type="submit">delete</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
Loading…
Reference in New Issue
Block a user