Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2022.4.1 #385

Merged
merged 4 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2022.4</Version>
<Version>2022.4.1</Version>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion src/HonzaBotner.Discord.Services/Commands/EmoteCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public EmoteCommands(IEmojiCounterService emojiCounterService)
[SlashCommandPermissions(Permissions.ManageEmojis)]
public async Task EmoteStatsCommandAsync(
InteractionContext ctx,
[Option("display", "Display as total instead of perDay?")] bool total = true,
[Option("display", "Display as total instead of perDay?")] bool total = false,
[Option("type", "What type of emojis to show? Defaults all")] DisplayTypes type = DisplayTypes.All)
{
IEnumerable<CountedEmoji> results = await _emojiCounterService.ListAsync();
Expand Down
7 changes: 6 additions & 1 deletion src/HonzaBotner.Discord.Services/Commands/MessageCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task ReactToMessageCommandAsync(
DiscordGuild guild = ctx.Guild;
DiscordMessage? oldMessage = await DiscordHelper.FindMessageFromLink(guild, url);

if (oldMessage == null)
if (oldMessage is null)
{
await ctx.CreateResponseAsync("Could not find message to react to.");
return;
Expand All @@ -135,6 +135,11 @@ await ctx.EditResponseAsync(
new DiscordWebhookBuilder()
.WithContent("Bot cannot react with provided emoji. Is it universal/from this server?"));
}
catch (UnauthorizedException)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Too many reactions"));
return;
}

response = await interactivity.WaitForReactionAsync(reactionCatch, ctx.User, TimeSpan.FromMinutes(2));
}
Expand Down
20 changes: 16 additions & 4 deletions src/HonzaBotner.Discord.Services/Commands/ModerationCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
Expand Down Expand Up @@ -130,10 +131,21 @@ public async Task ListCommandAsync(

List<(string, string)> embedFields = allWarnings.ConvertAll(warning =>
{
string target = ctx.Guild.GetMemberAsync(warning.UserId).Result?.DisplayName ?? warning.UserId.ToString();
string issuer = ctx.Guild.GetMemberAsync(warning.IssuerId).Result?.DisplayName ??
warning.IssuerId.ToString();
return ($"#{warning.Id}\t{target}\t{warning.IssuedAt}\t{issuer}", warning.Reason);
DiscordMember? target = null;
DiscordMember? issuer = null;
try
{
issuer = ctx.Guild.GetMemberAsync(warning.IssuerId).Result;
target = ctx.Guild.GetMemberAsync(warning.UserId).Result;
}
catch (NotFoundException)
{
}

return ($"#{warning.Id}\t" +
$"{target?.DisplayName ?? warning.UserId.ToString()}\t" +
$"{warning.IssuedAt}\t" +
$"{issuer?.DisplayName ?? warning.IssuerId.ToString()}", warning.Reason);
});

if (!embedFields.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Chronic.Core;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity.Enums;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
using HonzaBotner.Discord.Services.Jobs;
using HonzaBotner.Services.Contract;
Expand Down Expand Up @@ -34,14 +37,29 @@ public async Task ListConfigCommandAsync(InteractionContext ctx)

DiscordEmbedBuilder builder = new() { Title = "News List" };
builder.WithTimestamp(DateTime.Now);

StringBuilder stringBuilder = new("\n");

foreach (NewsConfig config in configs)
{
string active = GetActiveEmoji(config);
builder.AddField($"{active} {config.Name} [{config.Id}]",
$"Last fetched: {config.LastFetched}");
stringBuilder.Append($"{active} {config.Name} [{config.Id}]");
stringBuilder.Append($"Last fetched: {config.LastFetched}");
stringBuilder.AppendLine();
}

await ctx.CreateResponseAsync(builder.Build());

var interaction = ctx.Client.GetInteractivity();
var pages = interaction.GeneratePagesInEmbed(stringBuilder.ToString(), SplitType.Line, builder).ToList();

if (!pages.Any())
{
await ctx.CreateResponseAsync("No configs set", true);
return;
}


await interaction.SendPaginatedResponseAsync(ctx.Interaction, false, ctx.User, pages);
}


Expand Down Expand Up @@ -83,9 +101,18 @@ public async Task ToggleConfigCommandAsync(InteractionContext context,
public async Task AddConfigCommandAsync(InteractionContext ctx,
[Option("name", "Name of the news config")] string name,
[Option("source", "Source identification")] string source,
[Option("channels", "Channels where news will be published")] string channels)
[Option("channels", "Channels where news will be published")] string channels,
[Option("since", "Date and time of oldest news fetched")] string rawDateTime)
{
NewsConfig config = new(default, name, source, DateTime.MinValue, NewsProviderType.Courses, PublisherType.DiscordEmbed,
DateTime? parsedDateTime = ParseDateTime(rawDateTime);

if (parsedDateTime is null)
{
await ctx.CreateResponseAsync("Invalid datetime format", true);
return;
}

NewsConfig config = new(default, name, source, parsedDateTime.Value, NewsProviderType.Courses, PublisherType.DiscordEmbed,
true, ctx.ResolvedChannelMentions.Select(ch => ch.Id).ToArray());

await _configService.AddOrUpdate(config);
Expand All @@ -112,7 +139,7 @@ public async Task EditLastRunConfigCommandAsync(InteractionContext ctx,
{
DateTime? lastRun = ParseDateTime(rawDateTime);

if (lastRun is null || lastRun <= DateTime.UtcNow)
if (lastRun is null)
{
await ctx.CreateResponseAsync("Invalid last-run format");
return;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ await channel.GetMessagesBeforeAsync(messageList.Last().Id)
}

await channel.SendMessageAsync($@"
Stand-up time, ||o prázdninách se nepinguje||!
Stand-up time, <@&{_commonOptions.StandUpRoleId}>!

Results from <t:{((DateTimeOffset)today.AddDays(-1)).ToUnixTimeSeconds()}:D>:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class CommonCommandOptions
public ulong ModRoleId { get; set; }
public ulong AuthenticatedRoleId { get; set; }

public ulong MuteRoleId { get; set; }
public ulong BotRoleId { get; set; }
public string? HugEmoteName { get; set; }

Expand Down
1 change: 0 additions & 1 deletion src/HonzaBotner.Discord/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ private Task Client_ChannelCreated(DiscordClient client, ChannelCreateEventArgs

private Task Client_ThreadCreated(DiscordClient client, ThreadCreateEventArgs args)
{
Task.Run(() => args.Thread.SendMessageAsync("Ping <@132599706747535360>"));
return _eventHandler.Handle(args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/HonzaBotner.Discord/DiscordWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public DiscordWrapper(IOptions<DiscordConfig> options, IServiceProvider services
};
Commands = Client.UseSlashCommands(sConfig);

Client.Logger.LogInformation("Starting with secret: {Token}", options.Value.Token);
Client.Logger.LogInformation("Starting Bot");
}
}
1 change: 0 additions & 1 deletion src/HonzaBotner/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void ConfigureServices(IServiceCollection services)
.AddEventHandler<BoosterHandler>()
.AddEventHandler<EmojiCounterHandler>()
.AddEventHandler<HornyJailHandler>()
.AddEventHandler<NewChannelHandler>()
.AddEventHandler<PinHandler>()
.AddEventHandler<ReminderReactionsHandler>()
.AddEventHandler<RoleBindingsHandler>(EventHandlerPriority.High)
Expand Down
1 change: 0 additions & 1 deletion src/HonzaBotner/appsettings.BotDev.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"ModRoleId": 811385023705645086,
"BotRoleId": 493947307427889152,
"AuthenticatedRoleId": 809436691470614539,
"MuteRoleId": 0,
"HugEmoteName": "",
"BoosterRoleId": 0,
"GentlemenChannelId": 0,
Expand Down
1 change: 0 additions & 1 deletion src/HonzaBotner/appsettings.CvutFit.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"ModRoleId": 366970860550225950,
"BotRoleId": 493947307427889152,
"AuthenticatedRoleId": 681559148546359432,
"MuteRoleId": 750276752663904306,
"HugEmoteName": "peepoHugger",
"BoosterRoleId": 648686713845055489,
"GentlemenChannelId": 756616473283133551,
Expand Down
1 change: 0 additions & 1 deletion src/HonzaBotner/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"ModRoleId": 887978558759264296,
"BotRoleId": 887978852930953246,
"AuthenticatedRoleId": 887977978712174622,
"MuteRoleId": 0,
"HugEmoteName": "",
"BoosterRoleId": 820565262095876158,
"GentlemenChannelId": 820299208120336415,
Expand Down