mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-22 05:54:36 +00:00
Add announce message check; update output
Oops, I thought I pushed this a long time ago... pushing now to avoid complications
This commit is contained in:
parent
4fc2d901f4
commit
adc6006175
2 changed files with 38 additions and 11 deletions
|
@ -5,7 +5,7 @@
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>3.2.5</Version>
|
<Version>3.2.6</Version>
|
||||||
<Authors>NoiTheCat</Authors>
|
<Authors>NoiTheCat</Authors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ internal class ManagerCommands : CommandsCommon {
|
||||||
{
|
{
|
||||||
("config", CmdConfigDispatch),
|
("config", CmdConfigDispatch),
|
||||||
("override", CmdOverride),
|
("override", CmdOverride),
|
||||||
("check", CmdCheck)
|
("check", CmdCheck),
|
||||||
|
("test", CmdCheck)
|
||||||
};
|
};
|
||||||
|
|
||||||
#region Documentation
|
#region Documentation
|
||||||
|
@ -385,21 +386,24 @@ internal class ManagerCommands : CommandsCommon {
|
||||||
var result = new StringBuilder();
|
var result = new StringBuilder();
|
||||||
var guild = reqChannel.Guild;
|
var guild = reqChannel.Guild;
|
||||||
var conf = await GuildConfiguration.LoadAsync(guild.Id, true).ConfigureAwait(false);
|
var conf = await GuildConfiguration.LoadAsync(guild.Id, true).ConfigureAwait(false);
|
||||||
|
var userbdays = await GuildUserConfiguration.LoadAllAsync(guild.Id).ConfigureAwait(false);
|
||||||
|
|
||||||
|
result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{instance.ShardId:00}`");
|
||||||
|
result.AppendLine($"Number of registered birthdays: `{ userbdays.Count() }`");
|
||||||
|
result.AppendLine($"Server time zone: `{ (conf?.TimeZone ?? "Not set - using UTC") }`");
|
||||||
|
result.AppendLine();
|
||||||
|
|
||||||
result.AppendLine($"Server ID: {guild.Id} | Bot shard ID: {instance.ShardId:00}");
|
|
||||||
bool hasMembers = Common.HasMostMembersDownloaded(guild);
|
bool hasMembers = Common.HasMostMembersDownloaded(guild);
|
||||||
result.Append(DoTestFor("Bot has obtained the user list", () => hasMembers));
|
result.Append(DoTestFor("Bot has obtained the user list", () => hasMembers));
|
||||||
result.AppendLine($" - Has {guild.DownloadedMemberCount} of {guild.MemberCount} members.");
|
result.AppendLine($" - Has `{guild.DownloadedMemberCount}` of `{guild.MemberCount}` members.");
|
||||||
int bdayCount = -1;
|
int bdayCount = -1;
|
||||||
result.Append(DoTestFor("Check if users have a birthday today", delegate {
|
result.Append(DoTestFor("Birthday processing", delegate {
|
||||||
if (!hasMembers) return false;
|
if (!hasMembers) return false;
|
||||||
var gc = GuildConfiguration.LoadAsync(guild.Id, true).ConfigureAwait(false).GetAwaiter().GetResult();
|
bdayCount = BackgroundServices.BirthdayRoleUpdate.GetGuildCurrentBirthdays(userbdays, conf?.TimeZone).Count;
|
||||||
var users = GuildUserConfiguration.LoadAllAsync(guild.Id).ConfigureAwait(false).GetAwaiter().GetResult();
|
|
||||||
bdayCount = BackgroundServices.BirthdayRoleUpdate.GetGuildCurrentBirthdays(users, gc?.TimeZone).Count;
|
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
if (hasMembers) result.AppendLine($" - {bdayCount} user(s) currently having a birthday.");
|
if (hasMembers) result.AppendLine($" - `{bdayCount}` user(s) currently having a birthday.");
|
||||||
else result.AppendLine(" - Cannot check without user list.");
|
else result.AppendLine(" - Previous step failed.");
|
||||||
result.AppendLine();
|
result.AppendLine();
|
||||||
|
|
||||||
result.AppendLine(DoTestFor("Birthday role set with `bb.config role`", delegate {
|
result.AppendLine(DoTestFor("Birthday role set with `bb.config role`", delegate {
|
||||||
|
@ -427,7 +431,30 @@ internal class ManagerCommands : CommandsCommon {
|
||||||
return guild.CurrentUser.GetPermissions(channel).SendMessages;
|
return guild.CurrentUser.GetPermissions(channel).SendMessages;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await reqChannel.SendMessageAsync(result.ToString()).ConfigureAwait(false);
|
await reqChannel.SendMessageAsync(embed: new EmbedBuilder() {
|
||||||
|
Author = new EmbedAuthorBuilder() { Name = "Status and config check" },
|
||||||
|
Description = result.ToString()
|
||||||
|
}.Build()).ConfigureAwait(false);
|
||||||
|
|
||||||
|
const int announceMsgPreviewLimit = 350;
|
||||||
|
static string prepareAnnouncePreview(string announce) {
|
||||||
|
string trunc = announce.Length > announceMsgPreviewLimit ? announce[..announceMsgPreviewLimit] + "`(...)`" : announce;
|
||||||
|
var result = new StringBuilder();
|
||||||
|
foreach (var line in trunc.Split('\n'))
|
||||||
|
result.AppendLine($"> {line}");
|
||||||
|
return result.ToString();
|
||||||
|
}
|
||||||
|
if (conf != null && (conf.AnnounceMessages.Item1 != null || conf.AnnounceMessages.Item2 != null)) {
|
||||||
|
var em = new EmbedBuilder().WithAuthor(new EmbedAuthorBuilder() { Name = "Custom announce messages:" });
|
||||||
|
var dispAnnounces = new StringBuilder("Custom announcement message(s):\n");
|
||||||
|
if (conf.AnnounceMessages.Item1 != null) {
|
||||||
|
em = em.AddField("Single", prepareAnnouncePreview(conf.AnnounceMessages.Item1));
|
||||||
|
}
|
||||||
|
if (conf.AnnounceMessages.Item2 != null) {
|
||||||
|
em = em.AddField("Plural", prepareAnnouncePreview(conf.AnnounceMessages.Item2));
|
||||||
|
}
|
||||||
|
await reqChannel.SendMessageAsync(embed: em.Build()).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Common/helper methods
|
#region Common/helper methods
|
||||||
|
|
Loading…
Reference in a new issue