discord-v status fixs
This commit is contained in:
parent
3f85d1bae8
commit
108578656b
5 changed files with 64 additions and 53 deletions
|
|
@ -210,62 +210,65 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
|
||||
protected async Task DiscordRebuildChannels()
|
||||
{
|
||||
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 (catmap.ContainsKey(fcat.Name) == false)
|
||||
if (DiscordServer != null)
|
||||
{
|
||||
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);
|
||||
catmap.Add(fcat.Name, fcat);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
foreach (string A in required_cats)
|
||||
{
|
||||
required_cats.Remove(fcat.Name);
|
||||
}
|
||||
}
|
||||
foreach (string A in required_cats)
|
||||
{
|
||||
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GroupChannels.Contains(chan.Name) == false)
|
||||
ICategoryChannel newcat = await DiscordServer.CreateCategoryAsync(A).ConfigureAwait(true);
|
||||
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)
|
||||
{
|
||||
if (chan.CategoryId == catmap["group"].Id)
|
||||
required_channels.Remove(chan.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GroupChannels.Contains(chan.Name) == false)
|
||||
{
|
||||
GroupChannels.Add(chan.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
if (chan.CategoryId == catmap["group"].Id)
|
||||
{
|
||||
GroupChannels.Add(chan.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (string A in required_channels)
|
||||
{
|
||||
string groupname = G.Name.ToLowerInvariant();
|
||||
groupname = String.Concat(groupname.Where(char.IsLetterOrDigit));
|
||||
if (GroupChannels.Contains(groupname) == false)
|
||||
_ = await FindTextChannel(A, catmap["bot"], UUID.Zero, "bot").ConfigureAwait(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
if (myconfig.DiscordFull_Enable == true)
|
||||
{
|
||||
_ = StartDiscordClientService();
|
||||
login_bot(false);
|
||||
keep_alive();
|
||||
}
|
||||
else
|
||||
|
|
@ -68,9 +67,12 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
|
||||
protected override void login_bot(bool self_keep_alive)
|
||||
{
|
||||
controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive);
|
||||
controler.Bot.setDiscordClient(DiscordClient);
|
||||
attach_events();
|
||||
if (controler != null)
|
||||
{
|
||||
controler = new CliExitOnLogout(myconfig, running_as_docker, self_keep_alive);
|
||||
controler.Bot.setDiscordClient(DiscordClient);
|
||||
attach_events();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,11 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);
|
||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||
if (DiscordServer != null)
|
||||
{
|
||||
{
|
||||
if (myconfig.DiscordFull_Enable == true)
|
||||
{
|
||||
login_bot(false);
|
||||
}
|
||||
DiscordUnixTimeOnine = helpers.UnixTimeNow();
|
||||
DiscordClientConnected = true;
|
||||
await DiscordRebuildChannels();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
return await MarkMessage(message, "❌");
|
||||
}
|
||||
controler.Bot.KillMePlease();
|
||||
controler = null;
|
||||
return await MarkMessage(message, "✅").ConfigureAwait(false);
|
||||
}
|
||||
else if(message.Content == "exit")
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
protected bool discord_group_relay;
|
||||
protected DiscordSocketClient DiscordClient;
|
||||
protected bool DiscordClientConnected;
|
||||
|
||||
protected IGuild DiscordServer;
|
||||
protected string LastSendDiscordStatus = "";
|
||||
protected long DiscordUnixTimeOnine;
|
||||
|
|
|
|||
Loading…
Reference in a new issue