Skip to content

Commit 7ec295e

Browse files
Add /announce
1 parent 6f7b90a commit 7ec295e

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

Commands/AnnouncementCmds.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,88 @@ public async Task EditAnnounce(
407407

408408
await ctx.RespondWithModalAsync(new DiscordInteractionResponseBuilder().WithTitle("Edit Announcement").WithCustomId("editannounce-modal-callback").AddComponents(new DiscordTextInputComponent("New announcement text. Do not include roles!", "editannounce-modal-new-text", value: msg.Content, style: DiscordTextInputStyle.Paragraph)));
409409
}
410+
411+
[Command("announce")]
412+
[Description("Announces something in the current channel, pinging an Insider role in the process.")]
413+
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
414+
public async Task AnounceSlashCmd(SlashCommandContext ctx,
415+
[SlashChoiceProvider(typeof(WindowsVersionChoiceProvider))]
416+
[Parameter("windows_version"), Description("The Windows version to announce for.")] long windowsVersion,
417+
[SlashChoiceProvider(typeof(WindowsInsiderChannelChoiceProvider))]
418+
[Parameter("role1"), Description("The first Insider role to ping.")] string insiderChannel1,
419+
[Parameter("announcement_message"), Description("The message to announce.")] string announcementMessage,
420+
[SlashChoiceProvider(typeof(WindowsInsiderChannelChoiceProvider))]
421+
[Parameter("role2"), Description("The second Insider role to ping.")] string insiderChannel2 = "")
422+
{
423+
if (insiderChannel1 == insiderChannel2)
424+
{
425+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Both insider channels cannot be the same! Simply set one instead.", ephemeral: true);
426+
return;
427+
}
428+
429+
if (windowsVersion == 10 && insiderChannel1 != "RP")
430+
{
431+
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has a Release Preview Channel.", ephemeral: true);
432+
return;
433+
}
434+
435+
string roleKey1;
436+
if (windowsVersion == 10 && insiderChannel1 == "RP")
437+
{
438+
roleKey1 = "rp10";
439+
}
440+
else
441+
{
442+
roleKey1 = insiderChannel1.ToLower();
443+
}
444+
445+
await ctx.DeferResponseAsync(ephemeral: true);
446+
447+
DiscordRole insiderRole1 = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleKey1]);
448+
DiscordRole insiderRole2 = default;
449+
450+
if (insiderChannel2 != "")
451+
{
452+
string roleKey2;
453+
if (windowsVersion == 10 && insiderChannel2 == "RP")
454+
{
455+
roleKey2 = "rp10";
456+
}
457+
else if (windowsVersion == 10 && insiderChannel2 == "Beta")
458+
{
459+
roleKey2 = "beta10";
460+
}
461+
else
462+
{
463+
roleKey2 = insiderChannel2.ToLower();
464+
}
465+
466+
insiderRole2 = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleKey2]);
467+
}
468+
469+
await insiderRole1.ModifyAsync(mentionable: true);
470+
if (insiderRole2 != default)
471+
await insiderRole2.ModifyAsync(mentionable: true);
472+
473+
try
474+
{
475+
var msg = insiderRole1.Mention;
476+
if (insiderRole2 != default)
477+
msg += $" {insiderRole2.Mention}";
478+
msg += $" {announcementMessage}";
479+
await ctx.Channel.SendMessageAsync(msg);
480+
}
481+
catch
482+
{
483+
// We still need to remember to make it unmentionable even if the msg fails.
484+
}
485+
486+
await insiderRole1.ModifyAsync(mentionable: false);
487+
if (insiderRole2 != default)
488+
await insiderRole2.ModifyAsync(mentionable: false);
489+
490+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Announcement sent successfully!");
491+
}
410492

411493
[Command("announcetextcmd")]
412494
[TextAlias("announce")]

0 commit comments

Comments
 (0)