forked from adam/discord-bot-shtik
more details, more links, fixed a bug where it wouldn't give itself a seen-in-channel
This commit is contained in:
parent
e364b47c0f
commit
4bd51721b6
@ -114,7 +114,7 @@ public class DiscordInterface
|
|||||||
|
|
||||||
private async Task SelfConnected()
|
private async Task SelfConnected()
|
||||||
{
|
{
|
||||||
var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
|
var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel);
|
||||||
selfAccount.DisplayName = client.CurrentUser.Username;
|
selfAccount.DisplayName = client.CurrentUser.Username;
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
@ -150,7 +150,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, guild.Id);
|
var u = UpsertAccount(arg, guild);
|
||||||
u.DisplayName = arg.DisplayName;
|
u.DisplayName = arg.DisplayName;
|
||||||
}
|
}
|
||||||
private async Task ButtonHandler(SocketMessageComponent component)
|
private async Task ButtonHandler(SocketMessageComponent component)
|
||||||
@ -226,8 +226,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.Channel);
|
||||||
m.Author.SeenInChannel = m.Channel;
|
|
||||||
if(dMessage.Channel is IGuildChannel)
|
if(dMessage.Channel is IGuildChannel)
|
||||||
{
|
{
|
||||||
m.Author.DisplayName = (dMessage.Author as IGuildUser).DisplayName;//discord forgot how display names work.
|
m.Author.DisplayName = (dMessage.Author as IGuildUser).DisplayName;//discord forgot how display names work.
|
||||||
@ -301,9 +300,9 @@ 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, Channel inChannel)
|
||||||
{
|
{
|
||||||
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.SeenInChannel.Id == inChannel.Id);
|
||||||
if (acc == null)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
acc = new Account();
|
acc = new Account();
|
||||||
@ -313,6 +312,7 @@ public class DiscordInterface
|
|||||||
acc.ExternalId = user.Id.ToString();
|
acc.ExternalId = user.Id.ToString();
|
||||||
acc.IsBot = user.IsBot || user.IsWebhook;
|
acc.IsBot = user.IsBot || user.IsWebhook;
|
||||||
acc.Protocol = PROTOCOL;
|
acc.Protocol = PROTOCOL;
|
||||||
|
acc.SeenInChannel = inChannel;
|
||||||
|
|
||||||
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
|
||||||
if(acc.IsUser == null)
|
if(acc.IsUser == null)
|
||||||
|
@ -26,7 +26,7 @@ public class ChannelsController : Controller
|
|||||||
{
|
{
|
||||||
if(_db.Channels == null)
|
if(_db.Channels == null)
|
||||||
return Problem("Entity set '_db.Channels' is null.");
|
return Problem("Entity set '_db.Channels' is null.");
|
||||||
var channel = await _db.Channels.Include(u => u.ParentChannel).FirstAsync(u => u.Id == id);
|
var channel = await _db.Channels.Include(u => u.SubChannels).Include(u => u.Users).Include(u => u.ParentChannel).FirstAsync(u => u.Id == id);
|
||||||
var walker = channel;
|
var walker = channel;
|
||||||
while(walker != null)
|
while(walker != null)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
|
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
|
||||||
using vassago.Models;
|
using vassago.Models;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class HomeController : Controller
|
|||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
var allAccounts = _db.Accounts.ToList();
|
var allAccounts = _db.Accounts.ToList();
|
||||||
var allChannels = _db.Channels.ToList();
|
var allChannels = _db.Channels.Include(c => c.Users).ToList();
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("[");
|
sb.Append("[");
|
||||||
sb.Append("{text: \"channels\", nodes: [");
|
sb.Append("{text: \"channels\", nodes: [");
|
||||||
@ -41,11 +42,11 @@ public class HomeController : Controller
|
|||||||
|
|
||||||
serializeChannel(ref sb, ref allChannels, ref allAccounts, topLevelChannel);
|
serializeChannel(ref sb, ref allChannels, ref allAccounts, topLevelChannel);
|
||||||
}
|
}
|
||||||
sb.Append("]},");
|
sb.Append("]}");
|
||||||
|
|
||||||
if (allChannels.Any())
|
if (allChannels.Any())
|
||||||
{
|
{
|
||||||
sb.Append("{text: \"orphaned channels\", nodes: [");
|
sb.Append(",{text: \"orphaned channels\", nodes: [");
|
||||||
first = true;
|
first = true;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -63,11 +64,11 @@ public class HomeController : Controller
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.Append("]},");
|
sb.Append("]}");
|
||||||
}
|
}
|
||||||
if (allAccounts.Any())
|
if (allAccounts.Any())
|
||||||
{
|
{
|
||||||
sb.Append("{text: \"channelless accounts\", nodes: [");
|
sb.Append(",{text: \"channelless accounts\", nodes: [");
|
||||||
first = true;
|
first = true;
|
||||||
foreach (var acc in allAccounts)
|
foreach (var acc in allAccounts)
|
||||||
{
|
{
|
||||||
@ -84,13 +85,9 @@ public class HomeController : Controller
|
|||||||
sb.Append("]}");
|
sb.Append("]}");
|
||||||
}
|
}
|
||||||
var users = _db.Users.ToList();
|
var users = _db.Users.ToList();
|
||||||
if(topLevelChannels.Any() && users.Any())
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
}
|
|
||||||
if(users.Any())
|
if(users.Any())
|
||||||
{
|
{
|
||||||
sb.Append("{text: \"users\", nodes: [");
|
sb.Append(",{text: \"users\", nodes: [");
|
||||||
first=true;
|
first=true;
|
||||||
//refresh list; we'll be knocking them out again in serializeUser
|
//refresh list; we'll be knocking them out again in serializeUser
|
||||||
allAccounts = _db.Accounts.ToList();
|
allAccounts = _db.Accounts.ToList();
|
||||||
@ -117,7 +114,7 @@ public class HomeController : Controller
|
|||||||
allChannels.Remove(currentChannel);
|
allChannels.Remove(currentChannel);
|
||||||
//"but adam", you say, "there's an href attribute, why make a link?" because that makes the entire bar a link, and trying to expand the node will probably click the link
|
//"but adam", you say, "there's an href attribute, why make a link?" because that makes the entire bar a link, and trying to expand the node will probably click the link
|
||||||
sb.Append($"{{\"text\": \"<a href=\\\"{Url.ActionLink(action: "Details", controller: "Channels", values: new {id = currentChannel.Id})}\\\">{currentChannel.DisplayName}</a>\"");
|
sb.Append($"{{\"text\": \"<a href=\\\"{Url.ActionLink(action: "Details", controller: "Channels", values: new {id = currentChannel.Id})}\\\">{currentChannel.DisplayName}</a>\"");
|
||||||
var theseAccounts = allAccounts.Where(a => a.SeenInChannel?.Id == currentChannel.Id);
|
var theseAccounts = allAccounts.Where(a => a.SeenInChannel?.Id == currentChannel.Id).ToList();
|
||||||
allAccounts.RemoveAll(a => a.SeenInChannel?.Id == currentChannel.Id);
|
allAccounts.RemoveAll(a => a.SeenInChannel?.Id == currentChannel.Id);
|
||||||
var first = true;
|
var first = true;
|
||||||
if (currentChannel.SubChannels != null || theseAccounts != null)
|
if (currentChannel.SubChannels != null || theseAccounts != null)
|
||||||
@ -140,7 +137,6 @@ public class HomeController : Controller
|
|||||||
}
|
}
|
||||||
if (theseAccounts != null)
|
if (theseAccounts != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
sb.Append(',');
|
sb.Append(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +166,11 @@ public class HomeController : Controller
|
|||||||
}
|
}
|
||||||
private void serializeUser(ref StringBuilder sb, ref List<Account> allAccounts, User currentUser)
|
private void serializeUser(ref StringBuilder sb, ref List<Account> allAccounts, User currentUser)
|
||||||
{
|
{
|
||||||
sb.Append($"{{\"text\": \"{currentUser.DisplayName}\", ");
|
sb.Append($"{{\"text\": " +
|
||||||
|
$"\"<a href=\\\"{Url.ActionLink(action: "Details", controller: "Users", values: new {id = currentUser.Id})}\\\">"
|
||||||
|
+ currentUser.DisplayName +
|
||||||
|
"</a>\", ");
|
||||||
|
// \"{currentUser.DisplayName}\", ");
|
||||||
var ownedAccounts = allAccounts.Where(a => a.IsUser == currentUser);
|
var ownedAccounts = allAccounts.Where(a => a.IsUser == currentUser);
|
||||||
sb.Append("nodes: [");
|
sb.Append("nodes: [");
|
||||||
sb.Append($"{{\"text\": \"owned accounts:\", \"expanded\":true, \"nodes\": [");
|
sb.Append($"{{\"text\": \"owned accounts:\", \"expanded\":true, \"nodes\": [");
|
||||||
|
@ -8,6 +8,7 @@ tree above.
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function getTree() {
|
function getTree() {
|
||||||
var tree = @Html.Raw(ViewData["treeString"]);
|
var tree = @Html.Raw(ViewData["treeString"]);
|
||||||
|
console.log(tree);
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user