Merge pull request #21 from NoiTheCat/dev/tweaks

Various tweaks and additions
This commit is contained in:
Noi 2022-03-23 12:23:58 -07:00 committed by GitHub
commit 586c11d540
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 21 deletions

View file

@ -221,7 +221,8 @@ public class BirthdayModule : BotModuleBase {
select new { select new {
UserId = (ulong)row.UserId, UserId = (ulong)row.UserId,
Month = row.BirthMonth, Month = row.BirthMonth,
Day = row.BirthDay Day = row.BirthDay,
Zone = row.TimeZone
}; };
var result = new List<ListItem>(); var result = new List<ListItem>();
@ -234,7 +235,8 @@ public class BirthdayModule : BotModuleBase {
BirthDay = row.Day, BirthDay = row.Day,
DateIndex = DateIndex(row.Month, row.Day), DateIndex = DateIndex(row.Month, row.Day),
UserId = guildUser.Id, UserId = guildUser.Id,
DisplayName = Common.FormatName(guildUser, false) DisplayName = Common.FormatName(guildUser, false),
TimeZone = row.Zone
}); });
} }
return result; return result;
@ -254,6 +256,7 @@ public class BirthdayModule : BotModuleBase {
writer.Write(item.UserId); writer.Write(item.UserId);
writer.Write(" " + user.Username + "#" + user.Discriminator); writer.Write(" " + user.Username + "#" + user.Discriminator);
if (user.Nickname != null) writer.Write(" - Nickname: " + user.Nickname); if (user.Nickname != null) writer.Write(" - Nickname: " + user.Nickname);
if (item.TimeZone != null) writer.Write(" | Time zone: " + item.TimeZone);
writer.WriteLine(); writer.WriteLine();
} }
writer.Flush(); writer.Flush();
@ -267,7 +270,7 @@ public class BirthdayModule : BotModuleBase {
var writer = new StreamWriter(result, Encoding.UTF8); var writer = new StreamWriter(result, Encoding.UTF8);
// Conforming to RFC 4180; with header // Conforming to RFC 4180; with header
writer.Write("UserId,Username,Nickname,MonthDayDisp,Month,Day"); writer.Write("UserId,Username,Nickname,MonthDayDisp,Month,Day,TimeZone");
writer.Write("\r\n"); // crlf line break is specified by the standard writer.Write("\r\n"); // crlf line break is specified by the standard
foreach (var item in list) { foreach (var item in list) {
var user = guild.GetUser(item.UserId); var user = guild.GetUser(item.UserId);
@ -283,6 +286,8 @@ public class BirthdayModule : BotModuleBase {
writer.Write(item.BirthMonth); writer.Write(item.BirthMonth);
writer.Write(','); writer.Write(',');
writer.Write(item.BirthDay); writer.Write(item.BirthDay);
writer.Write(',');
writer.Write(item.TimeZone);
writer.Write("\r\n"); writer.Write("\r\n");
} }
writer.Flush(); writer.Flush();
@ -325,6 +330,7 @@ public class BirthdayModule : BotModuleBase {
public int BirthDay; public int BirthDay;
public ulong UserId; public ulong UserId;
public string DisplayName; public string DisplayName;
public string? TimeZone;
} }
#endregion #endregion
} }

View file

@ -193,7 +193,7 @@ public class ConfigModule : BotModuleBase {
var result = new StringBuilder(); var result = new StringBuilder();
result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{Shard.ShardId:00}`"); result.AppendLine($"Server ID: `{guild.Id}` | Bot shard ID: `{Shard.ShardId:00}`");
result.AppendLine($"Number of registered birthdays: `{ guildconf.UserEntries.Count() }`"); result.AppendLine($"Number of registered birthdays: `{ guildconf.UserEntries.Count }`");
result.AppendLine($"Server time zone: `{ (guildconf.TimeZone ?? "Not set - using UTC") }`"); result.AppendLine($"Server time zone: `{ (guildconf.TimeZone ?? "Not set - using UTC") }`");
result.AppendLine(); result.AppendLine();

View file

@ -132,9 +132,10 @@ class BirthdayRoleUpdate : BackgroundService {
if (!toApply.Contains(user.Id)) removals.Add(user); if (!toApply.Contains(user.Id)) removals.Add(user);
else no_ops.Add(user.Id); else no_ops.Add(user.Id);
} }
int removalAllowance = 15; // Limit removals per run, to not get continuously stuck on rate limits in misconfigured servers
foreach (var user in removals) { foreach (var user in removals) {
// TODO this gets hit with rate limits sometimes. figure something out.
await user.RemoveRoleAsync(r); await user.RemoveRoleAsync(r);
if (--removalAllowance == 0) break;
} }
foreach (var target in toApply) { foreach (var target in toApply) {
@ -146,7 +147,7 @@ class BirthdayRoleUpdate : BackgroundService {
} }
} catch (Discord.Net.HttpException ex) } catch (Discord.Net.HttpException ex)
when (ex.DiscordCode is DiscordErrorCode.MissingPermissions or DiscordErrorCode.InsufficientPermissions) { when (ex.DiscordCode is DiscordErrorCode.MissingPermissions or DiscordErrorCode.InsufficientPermissions) {
// Encountered access and/or permission issues despite earlier checks. Quit the loop here. // Encountered access and/or permission issues despite earlier checks. Quit the loop here, don't report error.
} }
return additions; return additions;
} }

View file

@ -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.3.1</Version> <Version>3.4.0</Version>
<Authors>NoiTheCat</Authors> <Authors>NoiTheCat</Authors>
</PropertyGroup> </PropertyGroup>
@ -30,7 +30,7 @@
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NodaTime" Version="3.0.9" /> <PackageReference Include="NodaTime" Version="3.0.10" />
<PackageReference Include="Npgsql" Version="6.0.3" /> <PackageReference Include="Npgsql" Version="6.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />

View file

@ -4,30 +4,47 @@
## Recognize birthdays in your Discord community! ## Recognize birthdays in your Discord community!
Birthday Bot is a simple, single-purpose bot. It will set a role on your users for the duration of their birthdays and, if desired, can announce a message in a channel of your choosing. Server owners can further specify a default time zone, with individual users also setting their own to ensure everyone's birthdays are recognized precisely on time. Birthday Bot is a simple, single-purpose bot. It will set a role on your users for the duration of their birthdays and, if desired, can
announce a message in a channel of your choosing. Server owners can further specify a default time zone, with individual users also setting
their own to ensure everyone's birthdays are recognized precisely on time.
#### Getting started #### Getting started
This bot requires a small amount of initial set-up before it's ready for use. To quickly get started, ensure that you: This bot requires a small amount of initial set-up before it's ready for use. To quickly get started, ensure that you:
* Create a dedicated birthday role to be used only by the bot. Ensure the new role is placed beneath the bot's own role. * Create a dedicated birthday role to be used only by the bot. Ensure the new role is placed beneath the bot's own role.
* **Do not use an existing role!** This bot assumes exclusive control over it. Users that have the role but are not having a birthday *will* be removed from it! * **Do not use an existing role!** This bot assumes exclusive control over it. Users that have the role but are not having a birthday
* Instruct the bot to use the role: `bb.config role (role name)` *will* be removed from it!
* Instruct the bot to use the role: `/config role set-birthday-role`
At this point, you may also wish to do the following optional steps: At this point, you may also wish to do the following optional steps:
* Set the birthday announcement channel: `bb.config channel (channel)` * Set the birthday announcement channel: `/config announce set-channel`
* Set a default time zone: `bb.config zone (time zone)` * Set a default time zone: `/config set-timezone`
* Use the command `bb.help-tzdata` for information on how to specify time zones. * Customize the announcement message: See `/config announce help` for more information.
* Customize the announcement message: See `bb.help-message` for more information.
#### Time zone support
You may specify a time zone in order to have your birthday recognized with respect to your local time. This bot only accepts zone names
from the IANA Time Zone Database (a.k.a. Olson Database).
* To find your zone: https://xske.github.io/tz/
* Interactive map: https://kevinnovak.github.io/Time-Zone-Picker/
* Complete list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#### Support the bot #### Support the bot
Birthday Bot is and shall remain fully free to use. I have no plans to hide any new or existing features behind pay-only, premium features. This is an independent hobby project and all costs associated with it come out of my pocket. Birthday Bot is and shall remain fully free to use. I have no plans to hide any new or existing features behind pay-only, premium features.
This is an independent hobby project and all costs associated with it come out of my pocket.
This bot has had a far greater response than I've ever expected, and at this point I find it difficult to pay for the server it runs on as its resource needs grow. I would greatly appreciate if you consider pitching in a little bit to cover my recurring costs by checking out my Ko-fi page: https://ko-fi.com/noithecat. This bot has had a far greater response than I've ever expected, and at this point I find it difficult to pay for the server it runs on as
its resource needs grow. I would greatly appreciate if you consider pitching in a little bit to cover my recurring costs by checking out my
Ko-fi page: https://ko-fi.com/noithecat.
#### Support, Privacy and Security #### Support, Privacy and Security
The support server for my bots can be accessed via the given link: https://discord.gg/JCRyFk7. Further information in setting up the bot can be found within it, as well as a small group of volunteers who are willing to answer questions. The support server for my bots can be accessed via the given link: https://discord.gg/JCRyFk7. Further information in setting up the bot
can be found within it, as well as a small group of volunteers who are willing to answer questions.
This bot collects and stores only information necessary for its operation, including user, server, and role IDs. This data is not stored indefinitely, and is removed after an extended period of lack of use. If an individual member of a server is not seen after 360 days, their data is purged. If the bot has been removed from a server, all existing data (including of its associated users) is purged after 180 days. This bot collects and stores only information necessary for its operation, including user, server, and role IDs. This data is not stored
indefinitely, but is removed after an extended period of lack of use. If an individual member of a server is not seen after 360 days, their
data is purged. If the bot has been removed from a server, all data (including of its associated users) is purged after 180 days.
Birthdays are not shared between servers that this same bot may be in. This is *by design*, for those preferring to share their birthdays with only certain communities instead of automatically sharing it to all of them. Users must enter their birthday information onto every server they share with the bot for the servers they wish for it to be known in. Birthdays are not shared between servers that this same bot may be in. This is *by design*, for those preferring to share their birthdays
with only certain communities instead of automatically sharing it to all of them. Users must enter their birthday information onto every
server they share with the bot for the servers they wish for it to be known in.
Any questions and concerns regarding data and security may be sent to the bot author via the support server or GitHub. Any questions and concerns regarding data and security may be sent to the bot author via the support server or GitHub.

View file

@ -34,7 +34,9 @@ internal class HelpInfoCommands : CommandsCommon {
// Normal section // Normal section
var cmdField = new EmbedFieldBuilder() { var cmdField = new EmbedFieldBuilder() {
Name = "Commands", Name = "Commands",
Value = $"{cpfx}help`, `{CommandPrefix}info`, `{CommandPrefix}help-tzdata`\n" Value = "----\n**Notice**: Text commands will soon be __removed__. "
+ "For a list of new commands, see this bot's `/help` command.\n----\n"
+ $"{cpfx}help`, `{CommandPrefix}info`, `{CommandPrefix}help-tzdata`\n"
+ $" » Help and informational messages.\n" + $" » Help and informational messages.\n"
+ ListingCommands.DocUpcoming.Export() + "\n" + ListingCommands.DocUpcoming.Export() + "\n"
+ UserCommands.DocSet.Export() + "\n" + UserCommands.DocSet.Export() + "\n"