Skip to content

Commit

Permalink
Merge pull request #21 from IzzyDotExe/unstable
Browse files Browse the repository at this point in the history
merge unstable
  • Loading branch information
IzzyDotExe authored Jun 18, 2023
2 parents 9e10975 + 4bf2817 commit beca150
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ARC/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static async Task StartDiscordBot(IConfigurationRoot settings)
_clientInstance = new DiscordClient(discordConfig)
{

ClientVersion = "2.2"
ClientVersion = "2.4"

};
_serviceProvider = ConfigureServices(settings);
Expand Down
30 changes: 22 additions & 8 deletions ARC/Schema/ArcDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,33 @@ public async Task SendMods(DiscordMessage message)

}

public async Task SendModmailMenu()
public async Task SendModmailMenu(Appeal? appeal = null)
{

var embed = new DiscordEmbedBuilder()

var embed = appeal == null?
new DiscordEmbedBuilder()
.WithModmailStyle()
.WithTitle("Mod Mail")
.WithDescription($"A Mod Mail session was opened by {Member.Mention}");

var buttons = new List<DiscordButtonComponent>() {
.WithDescription($"A Mod Mail session was opened by {Member.Mention}")
:
new DiscordEmbedBuilder()
.WithModmailStyle()
.WithTitle("Mod Mail")
.WithDescription($"Modmail for {Member.Mention}'s ban appeal");

var buttons = appeal == null?
new List<DiscordButtonComponent>() {
new DiscordButtonComponent(ButtonStyle.Secondary, $"modmail.save.{ModmailId}", "Save and Close", emoji: new DiscordComponentEmoji("📝")),
new DiscordButtonComponent(ButtonStyle.Danger, $"modmail.close.{ModmailId}", "Close", emoji: new DiscordComponentEmoji("🔒")),
//new DiscordButtonComponent(ButtonStyle.Danger, $"modmail.ban.{ModmailId}", "Ban", emoji: new DiscordComponentEmoji("🔨"))
};
new DiscordButtonComponent(ButtonStyle.Danger, $"modmail.ban.{ModmailId}", "Ban", emoji: new DiscordComponentEmoji("🔨"))
}
:
new List<DiscordButtonComponent>() {
new DiscordButtonComponent(ButtonStyle.Secondary, $"modmail.save.{ModmailId}", "Save and Close", emoji: new DiscordComponentEmoji("📝")),
new DiscordButtonComponent(ButtonStyle.Danger, $"modmail.close.{ModmailId}", "Close", emoji: new DiscordComponentEmoji("🔒")),
// new DiscordButtonComponent(ButtonStyle.Success, $"banappeal.unban.{appeal.AppealId}", "Unban", false, new DiscordComponentEmoji("🔓")),
// new DiscordButtonComponent(ButtonStyle.Danger, $"banappeal.deny.{appeal.AppealId}", "Deny", false, new DiscordComponentEmoji("🔨")),
};

DiscordMessageBuilder message = new DiscordMessageBuilder()
.WithEmbed(embed)
Expand Down
4 changes: 2 additions & 2 deletions ARC/Services/BanAppealService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessag

await modmail.SendUserSystem(@$"Hello! You're receiving this modmail because you appealed your ban in {guild.Name}
The moderators would like to have a chat about your appeal. You will recieve messsages shortly.");
await modmail.SendModmailMenu();
await modmail.SendModmailMenu(appeal);
}

private async Task HandleAppealAccept(ComponentInteractionCreateEventArgs args)
Expand Down Expand Up @@ -211,7 +211,7 @@ await args.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessag
var guild = await ClientInstance.GetGuildAsync(appealGuildSnowflake);

var msg = args.Message.Embeds[0];

var mbuilder= new DiscordInteractionResponseBuilder()
.AddEmbed(new DiscordEmbedBuilder(msg)
.WithColor(DiscordColor.Red)
Expand Down
86 changes: 63 additions & 23 deletions ARC/Services/ModMailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,37 @@ public ModMailService() : base("Modmail")
{
ClientInstance.MessageCreated += ClientInstanceOnMessageCreated;
ClientInstance.ComponentInteractionCreated += ClientInstance_ComponentInteractionCreated;
ClientInstance.ModalSubmitted += ClientInstanceOnModalSubmitted;
}

private async Task ClientInstanceOnModalSubmitted(DiscordClient sender, ModalSubmitEventArgs args)
{

var eventId = args.Interaction.Data.CustomId;

if (!eventId.StartsWith("modmail"))
return;

var eventAction = ClientInstance.GetEventAction(eventId);

if (eventAction == null)
return;

var modmail = DbContext.Modmails.Where(x => x.ModmailId == long.Parse(eventAction.Value.Item2)).First();

switch (eventAction.Value.Item1)
{
case "modmail.ban.confirm":
await args.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, new DiscordInteractionResponseBuilder().WithContent("Banning user..."));
var member = modmail.Member;
await SaveModMailSession(modmail, args.Interaction.User);
await CloseModMailSession(modmail, args.Interaction.User);
await BanMailUser(member, args.Values["modmail.ban.reason"]);
break;
}

await args.Interaction.CreateResponseAsync(InteractionResponseType.Pong, new DiscordInteractionResponseBuilder());

}

private async Task ClientInstance_ComponentInteractionCreated(DiscordClient sender, ComponentInteractionCreateEventArgs args)
Expand Down Expand Up @@ -44,23 +75,16 @@ private async Task ClientInstance_ComponentInteractionCreated(DiscordClient send
await SaveModMailSession(modmail, args.Interaction.User);
await CloseModMailSession(modmail, args.Interaction.User);
break;
/*
case "modmail.ban.confirm":
await SaveModMailSession(modmail);
await CloseModMailSession(modmail);
await BanMailUser(modmail);
break;

case "modmail.ban":
await ConfirmBanUser(args.Interaction);
await ConfirmBanUser(modmail, args.Interaction);
break;
*/

default:
break;

}



}

private async Task ClientInstanceOnMessageCreated(DiscordClient sender, MessageCreateEventArgs e)
Expand Down Expand Up @@ -190,21 +214,37 @@ private async Task SaveModMailSession(Modmail modmail, DiscordUser saver)
await transcrpt.SendMessageAsync(embed);

}

private async Task BanMailUser(DiscordMember member, string reason)
{
var Author = Arc.ClientInstance.CurrentUser;

/*
private async Task BanMailUser(Modmail modmail)
{
await modmail.Member.BanAsync();
}
var embed = new DiscordEmbedBuilder()
.WithModmailStyle()
.WithAuthor(Author.Username, "", Author.AvatarUrl)
.WithDescription($"You have been banned in {member.Guild.Name} for: ``{reason}``")
.Build();

private async Task ConfirmBanUser(DiscordInteraction interaction)
await member.SendMessageAsync(embed);
await member.BanAsync(reason: "Banned during modmail for: "+reason);
}

private async Task ConfirmBanUser(Modmail modmail, DiscordInteraction interaction)
{

var resp = new DiscordInteractionResponseBuilder()
{
await interaction.CreateResponseAsync(InteractionResponseType.Modal, new()
{
Content = "Are you sure you want to ban this user?"
});
}
*/

Title = "Are you sure you want to ban this user?",
CustomId = $"modmail.ban.confirm.{modmail.ModmailId}"

}.AddComponents(new TextInputComponent(label: "Reason",
customId: $"modmail.ban.reason",
placeholder: "reason",
required: true, max_length: 30));

await interaction.CreateResponseAsync(InteractionResponseType.Modal, resp);

}

}

0 comments on commit beca150

Please sign in to comment.