Skip to content

Commit

Permalink
feat!: bump versions + add custom webhook name/avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
0b10000 committed Feb 17, 2023
1 parent cc52cbb commit e14f36c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class Config : IConfig
[Description("Duration (in seconds) of how long the kill notification should last.")]
public float NotifyHintDuration { get; set; } = 10;

[Description("The name to use for the webhook.")]
public string WebhookName { get; set; } = "Kill Logs";

[Description("The URL to use for the webhook avatar.")]
public string WebhookAvatarUrl { get; set; } = "https://via.placeholder.com/150.png";

public bool Debug { get; set; } = false;

}
Expand Down
1 change: 0 additions & 1 deletion EventHandlers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using Exiled.API.Features;
using Exiled.Events.EventArgs;
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Server;
using Exiled.Permissions.Extensions;
Expand Down
2 changes: 1 addition & 1 deletion KillLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DSharp4Webhook" Version="2.0.1" />
<PackageReference Include="EXILED" Version="6.0.0-beta.20" />
<PackageReference Include="EXILED" Version="6.0.0-beta.26" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
9 changes: 7 additions & 2 deletions LogManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Text;
using Exiled.API.Features;
using Exiled.Events.EventArgs;
using Exiled.Events.EventArgs.Player;
using KillLogs.Enums;

Expand Down Expand Up @@ -48,7 +47,13 @@ public void ReportKill(DyingEventArgs ev, LogReason reason, bool sendImmediately

private void SendQueue()
{
plugin.KillWebhook.SendMessage(_queue.ToString())
plugin.MessageBuilder.Reset();
plugin.MessageBuilder.AvatarUrl = plugin.Config.WebhookAvatarUrl;
plugin.MessageBuilder.Username = plugin.Config.WebhookName;
plugin.MessageBuilder.Append(_queue.ToString());
var message = plugin.MessageBuilder.Build();

plugin.KillWebhook.SendMessage(message)
.Queue(() => Log.Debug($"Sent queue of length {_queue.Length}"));

_queue.Clear();
Expand Down
8 changes: 7 additions & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using DSharp4Webhook.Core;
using DSharp4Webhook.Core.Constructor;
using Exiled.API.Features;
using MapEvents = Exiled.Events.Handlers.Map;
using PlayerEvents = Exiled.Events.Handlers.Player;
Expand All @@ -19,7 +20,7 @@ public class Plugin : Plugin<Config>
public override string Author => "0b10000";
public override string Name => "KillLogs";
public override string Prefix => "KillLogs";
public override Version Version { get; } = new(4, 0, 0);
public override Version Version { get; } = new(5, 0, 0);
public override Version RequiredExiledVersion { get; } = new(6, 0, 0);

private EventHandlers EventHandlers { get; set; }
Expand All @@ -30,6 +31,8 @@ public class Plugin : Plugin<Config>
private WebhookProvider WebhookProvider { get; set; }
internal IWebhook KillWebhook { get; set; }

internal MessageBuilder MessageBuilder { get; set; }

internal List<Player> PlayersToNotify { get; set; }

public override void OnEnabled()
Expand All @@ -42,6 +45,9 @@ public override void OnEnabled()

WebhookProvider = new WebhookProvider("0b10000.kill_logs");
WebhookProvider.AllowedMention = AllowedMention.ROLES;

MessageBuilder = ConstructorProvider.GetMessageBuilder();

KillWebhook = WebhookProvider.CreateWebhook(Config.DiscordWebhookUrl);

PlayerEvents.Dying += EventHandlers.OnDying;
Expand Down

0 comments on commit e14f36c

Please sign in to comment.