Skip to content

Commit

Permalink
Merge pull request #27 from rarDevelopment/dev
Browse files Browse the repository at this point in the history
add link command, update references to the site
  • Loading branch information
rarDevelopment authored Jan 15, 2024
2 parents 39e172d + 37b569e commit 1ee0cd4
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion TimeZoneBot.BusinessLayer/TimeZoneBot.BusinessLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.13.0" />
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="NodaTime" Version="3.1.10" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions TimeZoneBot.DataLayer/TimeZoneBot.DataLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="MongoDB.Driver" Version="2.23.1" />
<PackageReference Include="NodaTime" Version="3.1.10" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions TimeZoneBot.Models/DiscordSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class DiscordSettings
{
public string? BotToken { get; set; }
public int? HourForBirthdayAnnouncements { get; set; }
public string? TimeZoneConfigWebsite { get; set; }
}
2 changes: 1 addition & 1 deletion TimeZoneBot.Models/TimeZoneBot.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NodaTime" Version="3.1.9" />
<PackageReference Include="NodaTime" Version="3.1.10" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions TimeZoneBot/Commands/LinkCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using DiscordDotNetUtilities.Interfaces;
using TimeZoneBot.Models;

namespace TimeZoneBot.Commands;

public class LinkCommand(IDiscordFormatter discordFormatter, DiscordSettings discordSettings)
: InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("link-to-timezone-site", "Get a link to the website where you can find and set your time zone.")]
public async Task LinkSlashCommand()
{
await RespondAsync(embed: discordFormatter.BuildRegularEmbedWithUserFooter(
"Click here to visit the site where you can find and set your time zone",
"You will have to log in with your Discord account and then click Settings under TimeZoneBot.",
Context.User,
url: discordSettings.TimeZoneConfigWebsite!));
}
}
6 changes: 4 additions & 2 deletions TimeZoneBot/Commands/SetDefaultTimeZoneCommand.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using DiscordDotNetUtilities.Interfaces;
using NodaTime;
using TimeZoneBot.BusinessLayer.Interfaces;
using TimeZoneBot.Models;

namespace TimeZoneBot.Commands;

public class SetDefaultTimeZoneCommand(IConfigurationBusinessLayer configurationBusinessLayer,
IDiscordFormatter discordFormatter,
DiscordSettings discordSettings,
ILogger<DiscordBot> logger)
: InteractionModuleBase<SocketInteractionContext>
{
[DefaultMemberPermissions(GuildPermission.Administrator)]
[SlashCommand("set-default-time-zone", "Set the default time zone for birthday checks when members have not set their time zone.")]
public async Task SetDefaultTimeZoneSlashCommand(
[Summary("time-zone", "Time Zone ID (visit https://rardk64.com/timezones/ and set your time zone there).")] string timeZoneName
[Summary("time-zone", "Time Zone ID (use /link to find)")] string timeZoneName
)
{
var member = Context.Guild.Users.FirstOrDefault(u => u.Id == Context.User.Id);
Expand All @@ -34,7 +36,7 @@ public async Task SetDefaultTimeZoneSlashCommand(
if (timeZone == null)
{
await FollowupAsync(embed: discordFormatter.BuildErrorEmbedWithUserFooter("Invalid Time Zone",
"The provided time zone was not valid. Please visit https://rardk64.com/timezones/ and set your time zone there, or copy it and set it here.",
$"The provided time zone was not valid. Please visit {discordSettings.TimeZoneConfigWebsite} and set your time zone there, or copy it and set it here.",
member));
return;
}
Expand Down
8 changes: 5 additions & 3 deletions TimeZoneBot/Commands/SetTimeZoneCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
using NodaTime;
using TimeZoneBot.BusinessLayer;
using TimeZoneBot.BusinessLayer.Interfaces;
using TimeZoneBot.Models;
using TimeZoneBot.Models.Exceptions;

namespace TimeZoneBot.Commands;

public class SetTimeZoneCommand(ITimeZoneBusinessLayer timeZoneBusinessLayer,
IDiscordFormatter discordFormatter,
DiscordSettings discordSettings,
ILogger<DiscordBot> logger)
: InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("set-time-zone", "Set your time zone.")]
[SlashCommand("set-time-zone", "Set your time zone (recommended: use /link to set this instead).")]
public async Task SetTimeZoneSlashCommand(
[Summary("time-zone", "Time Zone name (visit https://rardk64.com/timezones/ and set your time zone there).")]
[Summary("time-zone", "Time Zone ID")]
string timeZoneName)
{
var member = Context.Guild.Users.FirstOrDefault(u => u.Id == Context.User.Id);
Expand All @@ -29,7 +31,7 @@ public async Task SetTimeZoneSlashCommand(
if (timeZone == null)
{
await FollowupAsync(embed: discordFormatter.BuildErrorEmbedWithUserFooter("Invalid Time Zone",
"The provided time zone was not valid. Please visit https://rardk64.com/timezones/ and set your time zone there, or copy it and set it here.",
$"The provided time zone was not valid. Please visit {discordSettings.TimeZoneConfigWebsite} and set your time zone there, or copy it and set it here.",
member));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Task Handle(ReactionAddedNotification notification, CancellationToken can
{
logger.LogError(ex, "Error in ReactionAddedNotificationHandler");
await message.ReplyAsync(embed: discordFormatter.BuildErrorEmbedWithUserFooter("Error!",
"There was an error retrieving the time(s) for that user. Make sure the user has set up their timezone.", reactingUser), allowedMentions: AllowedMentions.None);
"There was an error retrieving the time(s) for that user. Make sure the user has set up their time zone.", reactingUser), allowedMentions: AllowedMentions.None);
return Task.CompletedTask;
}

Expand Down
3 changes: 2 additions & 1 deletion TimeZoneBot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
global using Microsoft.Extensions.Logging;
using DiscordDotNetUtilities;
using DiscordDotNetUtilities.Interfaces;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
Expand Down Expand Up @@ -54,7 +53,9 @@
{
BotToken = host.Configuration["Discord:BotToken"],
HourForBirthdayAnnouncements = Convert.ToInt32(host.Configuration["Discord:HourForBirthdayAnnouncements"]),
TimeZoneConfigWebsite = host.Configuration["Discord:TimeZoneConfigWebsite"],
};

var databaseSettings = new DatabaseSettings
{
Cluster = host.Configuration["Database:Cluster"],
Expand Down
6 changes: 3 additions & 3 deletions TimeZoneBot/TimeZoneBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Sgbj.Cron.CronTimer" Version="1.0.2" />
Expand Down
5 changes: 3 additions & 2 deletions TimeZoneBot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"Version": {
"VersionNumber": "7.7.0"
"VersionNumber": "7.8.0"
},
"Discord": {
"BotToken": "token",
"HourForBirthdayAnnouncements": 8
"HourForBirthdayAnnouncements": 8,
"TimeZoneConfigWebsite": "https://rardk.com/bots/timezonebot/"
},
"Database": {
"Cluster": "placeholder",
Expand Down

0 comments on commit 1ee0cd4

Please sign in to comment.