-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
178 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using DSharpPlus; | ||
using DSharpPlus.Entities; | ||
using ModCore.Commands; | ||
using ModCore.Database; | ||
using ModCore.Database.DatabaseEntities; | ||
using ModCore.Extensions.Abstractions; | ||
using ModCore.Extensions.Attributes; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ModCore.Modals | ||
{ | ||
[Modal("override_tag")] | ||
public class OverrideTagModal : IModal | ||
{ | ||
[ModalField("Tag Content (Markdown Permitted)", "content", "https://www.youtube.com/watch?v=dQw4w9WgXcQ", null, true, TextInputStyle.Paragraph, 1, 255)] | ||
public string Content { get; set; } | ||
|
||
[ModalHiddenField("n")] | ||
public string TagName { get; set; } | ||
|
||
private DatabaseContextBuilder Database; | ||
|
||
public OverrideTagModal(DatabaseContextBuilder database) | ||
{ | ||
this.Database = database; | ||
} | ||
|
||
public async Task HandleAsync(DiscordInteraction interaction) | ||
{ | ||
await interaction.DeferAsync(true); | ||
var member = await interaction.Guild.GetMemberAsync(interaction.User.Id); | ||
|
||
bool isNew = false; | ||
if (!Tags.tryGetTag(TagName, interaction.Channel, this.Database, out var tag) | ||
|| tag.ChannelId < 1) | ||
{ | ||
tag = new DatabaseTag() | ||
{ | ||
ChannelId = (long)interaction.Channel.Id, | ||
GuildId = (long)interaction.Guild.Id, | ||
Contents = Content, | ||
CreatedAt = DateTime.Now, | ||
Name = TagName, | ||
OwnerId = (long)interaction.User.Id | ||
}; | ||
isNew = true; | ||
} | ||
else if (!Tags.canManageTag(tag, interaction.Channel, member)) | ||
{ | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"⚠️ The tag {TagName} already exists and you can not manage it!")); | ||
return; | ||
} | ||
|
||
await using var db = this.Database.CreateContext(); | ||
tag.Contents = Content; | ||
if (isNew) | ||
{ | ||
db.Tags.Add(tag); | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"✅ Channel override tag `{TagName}` succesfully created")); | ||
} | ||
else | ||
{ | ||
db.Tags.Update(tag); | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"✅ Channel override tag `{TagName}` succesfully modified!")); | ||
} | ||
await db.SaveChangesAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using DSharpPlus; | ||
using DSharpPlus.Entities; | ||
using ModCore.Commands; | ||
using ModCore.Database; | ||
using ModCore.Database.DatabaseEntities; | ||
using ModCore.Extensions.Abstractions; | ||
using ModCore.Extensions.Attributes; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ModCore.Modals | ||
{ | ||
[Modal("set_tag")] | ||
public class SetTagModal : IModal | ||
{ | ||
[ModalField("Tag Content (Markdown Permitted)", "content", "https://www.youtube.com/watch?v=dQw4w9WgXcQ", null, true, TextInputStyle.Paragraph, 1, 255)] | ||
public string Content { get; set; } | ||
|
||
[ModalHiddenField("n")] | ||
public string TagName { get; set; } | ||
|
||
private DatabaseContextBuilder Database; | ||
|
||
public SetTagModal(DatabaseContextBuilder database) | ||
{ | ||
this.Database = database; | ||
} | ||
|
||
public async Task HandleAsync(DiscordInteraction interaction) | ||
{ | ||
await interaction.DeferAsync(true); | ||
|
||
bool isNew = false; | ||
var member = await interaction.Guild.GetMemberAsync(interaction.User.Id); | ||
|
||
if (Tags.tryGetTag(TagName, interaction.Channel, Database, out var tag)) | ||
{ | ||
if (!Tags.canManageTag(tag, interaction.Channel, member)) | ||
{ | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"⚠️ The tag {TagName} already exists and you can not manage it!")); | ||
return; | ||
} | ||
} | ||
else | ||
{ | ||
tag = new DatabaseTag | ||
{ | ||
ChannelId = -1, // guild tag | ||
Name = TagName, | ||
GuildId = (long)interaction.Guild.Id, | ||
OwnerId = (long)interaction.User.Id, | ||
CreatedAt = DateTime.Now | ||
}; | ||
isNew = true; | ||
} | ||
|
||
await using var db = this.Database.CreateContext(); | ||
tag.Contents = Content; | ||
if (isNew) | ||
{ | ||
db.Tags.Add(tag); | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"✅ Server-global tag `{TagName}` succesfully created!")); | ||
} | ||
else | ||
{ | ||
db.Tags.Update(tag); | ||
await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder() | ||
.WithContent($"✅ Server-global tag `{TagName}` succesfully modified!")); | ||
} | ||
await db.SaveChangesAsync(); | ||
} | ||
} | ||
} |