discord-v status fixs

This commit is contained in:
Madpeterz 2021-01-31 02:45:30 +00:00
parent 3f85d1bae8
commit 108578656b
5 changed files with 64 additions and 53 deletions

View file

@ -210,62 +210,65 @@ namespace BetterSecondBot.DiscordSupervisor
protected async Task DiscordRebuildChannels() protected async Task DiscordRebuildChannels()
{ {
List<string> required_cats = new List<string>() { "bot", "group", "im" }; if (DiscordServer != null)
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
foreach (ICategoryChannel fcat in found_cats)
{ {
if (catmap.ContainsKey(fcat.Name) == false) List<string> required_cats = new List<string>() { "bot", "group", "im" };
IReadOnlyCollection<ICategoryChannel> found_cats = await DiscordServer.GetCategoriesAsync(CacheMode.AllowDownload);
foreach (ICategoryChannel fcat in found_cats)
{ {
if (required_cats.Contains(fcat.Name) == true) if (catmap.ContainsKey(fcat.Name) == false)
{
if (required_cats.Contains(fcat.Name) == true)
{
required_cats.Remove(fcat.Name);
catmap.Add(fcat.Name, fcat);
}
}
else
{ {
required_cats.Remove(fcat.Name); required_cats.Remove(fcat.Name);
catmap.Add(fcat.Name, fcat);
} }
} }
else foreach (string A in required_cats)
{ {
required_cats.Remove(fcat.Name); ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
catmap.Add(A, newcat);
} }
} List<string> required_channels = new List<string>() { "status", "interface", "localchat" };
foreach (string A in required_cats) IReadOnlyCollection<ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);
{ List<string> GroupChannels = new List<string>();
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true); foreach (ITextChannel chan in found_chans)
catmap.Add(A, newcat);
}
List<string> required_channels = new List<string>() { "status", "interface","localchat" };
IReadOnlyCollection<ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);
List<string> GroupChannels = new List<string>();
foreach (ITextChannel chan in found_chans)
{
if (chan.CategoryId == catmap["bot"].Id)
{ {
required_channels.Remove(chan.Name); if (chan.CategoryId == catmap["bot"].Id)
}
else
{
if (GroupChannels.Contains(chan.Name) == false)
{ {
if (chan.CategoryId == catmap["group"].Id) required_channels.Remove(chan.Name);
}
else
{
if (GroupChannels.Contains(chan.Name) == false)
{ {
GroupChannels.Add(chan.Name); if (chan.CategoryId == catmap["group"].Id)
{
GroupChannels.Add(chan.Name);
}
} }
} }
} }
} foreach (string A in required_channels)
foreach (string A in required_channels)
{
_ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
}
if (HasBot() == true)
{
foreach (Group G in controler.Bot.MyGroups.Values)
{ {
string groupname = G.Name.ToLowerInvariant(); _ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(false);
groupname = String.Concat(groupname.Where(char.IsLetterOrDigit)); }
if (GroupChannels.Contains(groupname) == false)
if (HasBot() == true)
{
foreach (Group G in controler.Bot.MyGroups.Values)
{ {
_ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false); string groupname = G.Name.ToLowerInvariant();
groupname = String.Concat(groupname.Where(char.IsLetterOrDigit));
if (GroupChannels.Contains(groupname) == false)
{
_ = await FindTextChannel(groupname, catmap["group"], G.ID, "Group").ConfigureAwait(false);
}
} }
} }
} }

View file

@ -57,7 +57,6 @@ namespace BetterSecondBot.DiscordSupervisor
if (myconfig.DiscordFull_Enable == true) if (myconfig.DiscordFull_Enable == true)
{ {
_ = StartDiscordClientService(); _ = StartDiscordClientService();
login_bot(false);
keep_alive(); keep_alive();
} }
else else
@ -68,9 +67,12 @@ namespace BetterSecondBot.DiscordSupervisor
protected override void login_bot(bool self_keep_alive) protected override void login_bot(bool self_keep_alive)
{ {
controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive); if (controler != null)
controler.Bot.setDiscordClient(DiscordClient); {
attach_events(); controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive);
controler.Bot.setDiscordClient(DiscordClient);
attach_events();
}
} }
} }

View file

@ -28,6 +28,10 @@ namespace BetterSecondBot.DiscordSupervisor
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID); DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
if (DiscordServer != null) if (DiscordServer != null)
{ {
if (myconfig.DiscordFull_Enable == true)
{
login_bot(false);
}
DiscordUnixTimeOnine = helpers.UnixTimeNow(); DiscordUnixTimeOnine = helpers.UnixTimeNow();
DiscordClientConnected = true; DiscordClientConnected = true;
await DiscordRebuildChannels(); await DiscordRebuildChannels();

View file

@ -39,6 +39,7 @@ namespace BetterSecondBot.DiscordSupervisor
return await MarkMessage(message, "❌"); return await MarkMessage(message, "❌");
} }
controler.Bot.KillMePlease(); controler.Bot.KillMePlease();
controler = null;
return await MarkMessage(message, "✅").ConfigureAwait(false); return await MarkMessage(message, "✅").ConfigureAwait(false);
} }
else if(message.Content == "exit") else if(message.Content == "exit")

View file

@ -15,6 +15,7 @@ namespace BetterSecondBot.DiscordSupervisor
protected bool discord_group_relay; protected bool discord_group_relay;
protected DiscordSocketClient DiscordClient; protected DiscordSocketClient DiscordClient;
protected bool DiscordClientConnected; protected bool DiscordClientConnected;
protected IGuild DiscordServer; protected IGuild DiscordServer;
protected string LastSendDiscordStatus = ""; protected string LastSendDiscordStatus = "";
protected long DiscordUnixTimeOnine; protected long DiscordUnixTimeOnine;