something (#154)

* don`t notify if not ic channels

* allow all jobs to admin

* and i can give it all to you BABY

* fix cringers

* нерф лично для виктории мяукиной

* some tweaks + wonderbox update
This commit is contained in:
rhailrake
2023-06-07 22:06:21 +06:00
committed by Aviu00
parent 11c26811fa
commit 65a471cda8
9 changed files with 4035 additions and 3472 deletions

View File

@@ -172,7 +172,15 @@ public partial class ChatBox : UIWidget
_controller.UpdateSelectedChannel(this);
// Warn typing indicator about change
_controller.NotifyChatTextChange();
if (IsValidChannel())
{
_controller.NotifyChatTextChange();
}
}
private bool IsValidChannel()
{
return SelectedChannel is not (ChatSelectChannel.Admin or ChatSelectChannel.Dead or ChatSelectChannel.OOC or ChatSelectChannel.LOOC);
}
protected override void Dispose(bool disposing)

View File

@@ -1,4 +1,5 @@
using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Afk;
using Content.Server.Afk.Events;
using Content.Server.GameTicking;
@@ -31,6 +32,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly PlayTimeTrackingManager _tracking = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
public override void Initialize()
{
@@ -157,8 +159,16 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
_tracking.QueueSendTimers(ev.PlayerSession);
}
private bool IsBypassingChecks(ICommonSession player)
{
return _adminManager.IsAdmin(player, true);
}
public bool IsAllowed(ICommonSession player, string role)
{
if (IsBypassingChecks(player))
return true;
if (!_prototypes.TryIndex<JobPrototype>(role, out var job) ||
job.Requirements == null ||
!_cfg.GetCVar(CCVars.GameRoleTimers))
@@ -172,6 +182,10 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
public HashSet<string> GetDisallowedJobs(ICommonSession player)
{
var roles = new HashSet<string>();
if (IsBypassingChecks(player))
return roles;
if (!_cfg.GetCVar(CCVars.GameRoleTimers))
return roles;
@@ -203,6 +217,10 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
return;
var player = _playerManager.GetSessionByUserId(userId);
if (IsBypassingChecks(player))
return;
if (!_tracking.TryGetTrackerTimes(player, out var playTimes))
{
// Sorry mate but your playtimes haven't loaded.

View File

@@ -5,9 +5,10 @@ using System.Text.Json.Serialization;
using Content.Server.Maps;
using Content.Shared.GameTicking;
using Content.Shared.White;
using Robust.Shared;
using Robust.Shared.Configuration;
namespace Content.Server.Corvax.RoundNotifications;
namespace Content.Server.White.Discord;
/// <summary>
/// Listen game events and send notifications to Discord
@@ -20,10 +21,14 @@ public sealed class RoundNotificationsSystem : EntitySystem
private ISawmill _sawmill = default!;
private readonly HttpClient _httpClient = new();
private string _webhookUrl = String.Empty;
private string _roleId = String.Empty;
private string _webhookUrl = string.Empty;
private string _roleId = string.Empty;
private string _serverName = string.Empty;
private bool _roundStartOnly;
private const int EmbedColor = 0x6600FF;
private const int EmbedColorRestart = 0x00eb1f;
/// <inheritdoc/>
public override void Initialize()
{
@@ -34,29 +39,36 @@ public sealed class RoundNotificationsSystem : EntitySystem
_config.OnValueChanged(WhiteCVars.DiscordRoundWebhook, value => _webhookUrl = value, true);
_config.OnValueChanged(WhiteCVars.DiscordRoundRoleId, value => _roleId = value, true);
_config.OnValueChanged(WhiteCVars.DiscordRoundStartOnly, value => _roundStartOnly = value, true);
_config.OnValueChanged(CVars.GameHostName, value => _serverName = value, true);
_sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("notifications");
}
private void OnRoundRestart(RoundRestartCleanupEvent e)
{
if (String.IsNullOrEmpty(_webhookUrl))
if (string.IsNullOrEmpty(_webhookUrl))
return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var payload = new WebhookPayload()
{
Content = Loc.GetString("discord-round-new"),
Embeds = new List<Embed>
{
new()
{
Title = Loc.GetString("discord-round-embed-title", ("server", serverName)),
Description = Loc.GetString("discord-round-new"),
Color = EmbedColorRestart
}
}
};
if (!String.IsNullOrEmpty(_roleId))
if (!string.IsNullOrEmpty(_roleId))
{
payload = new WebhookPayload()
payload.Content = $"<@&{_roleId}>";
payload.AllowedMentions = new Dictionary<string, string[]>
{
Content = $"<@&{_roleId}> {Loc.GetString("discord-round-new")}",
AllowedMentions = new Dictionary<string, string[]>
{
{ "roles", new []{ _roleId } }
},
{ "roles", new[] { _roleId } }
};
}
@@ -65,30 +77,56 @@ public sealed class RoundNotificationsSystem : EntitySystem
private void OnRoundStarted(RoundStartedEvent e)
{
if (String.IsNullOrEmpty(_webhookUrl))
if (string.IsNullOrEmpty(_webhookUrl))
return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var map = _gameMapManager.GetSelectedMap();
var mapName = map?.MapName ?? Loc.GetString("discord-round-unknown-map");
var text = Loc.GetString("discord-round-start",
("id", e.RoundId),
("map", mapName));
var payload = new WebhookPayload() { Content = text };
var payload = new WebhookPayload()
{
Embeds = new List<Embed>
{
new()
{
Title = Loc.GetString("discord-round-embed-title", ("server", serverName)),
Description = text,
Color = EmbedColor
}
}
};
SendDiscordMessage(payload);
}
private void OnRoundEnded(RoundEndedEvent e)
{
if (String.IsNullOrEmpty(_webhookUrl) || _roundStartOnly)
if (string.IsNullOrEmpty(_webhookUrl) || _roundStartOnly)
return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var text = Loc.GetString("discord-round-end",
("id", e.RoundId),
("hours", e.RoundDuration.Hours),
("minutes", e.RoundDuration.Minutes),
("seconds", e.RoundDuration.Seconds));
var payload = new WebhookPayload() { Content = text };
var payload = new WebhookPayload()
{
Embeds = new List<Embed>
{
new()
{
Title = Loc.GetString("discord-round-embed-title", ("server", serverName)),
Description = text,
Color = EmbedColor
}
}
};
SendDiscordMessage(payload);
}
@@ -101,8 +139,8 @@ public sealed class RoundNotificationsSystem : EntitySystem
var content = await request.Content.ReadAsStringAsync();
if (!request.IsSuccessStatusCode)
{
_sawmill.Log(LogLevel.Error, $"Discord returned bad status code when posting message: {request.StatusCode}\nResponse: {content}");
return;
_sawmill.Log(LogLevel.Error,
$"Discord returned bad status code when posting message: {request.StatusCode}\nResponse: {content}");
}
}
@@ -111,6 +149,9 @@ public sealed class RoundNotificationsSystem : EntitySystem
[JsonPropertyName("content")]
public string Content { get; set; } = "";
[JsonPropertyName("embeds")]
public List<Embed>? Embeds { get; init; } = null;
[JsonPropertyName("allowed_mentions")]
public Dictionary<string, string[]> AllowedMentions { get; set; } =
new()
@@ -122,4 +163,21 @@ public sealed class RoundNotificationsSystem : EntitySystem
{
}
}
// https://discord.com/developers/docs/resources/channel#embed-object-embed-structure
private struct Embed
{
[JsonPropertyName("title")]
public string Title { get; init; } = "";
[JsonPropertyName("description")]
public string Description { get; init; } = "";
[JsonPropertyName("color")]
public int Color { get; init; } = 0;
public Embed()
{
}
}
}

View File

@@ -1,4 +1,5 @@
discord-round-new = Новый раунд скоро начнётся, поспеши!
discord-round-start = Раунд #{ $id } на карте "{ $map }" начался.
discord-round-end = Раунд #{ $id } закончился. Он длился { $hours } ч., { $minutes } мин., и { $seconds } сек.
discord-round-embed-title = SS14 | { $server }
discord-round-new = Новый раунд начинается!
discord-round-start = Раунд **#{ $id }** на карте **"{ $map }"** начался.
discord-round-end = Раунд **#{ $id }** закончился. Он длился **{ $hours } ч., { $minutes } мин., и { $seconds } сек.**
discord-round-unknown-map = Неизвестна

File diff suppressed because it is too large Load Diff

View File

@@ -50,7 +50,7 @@
icon: { sprite: /Textures/Objects/Weapons/Melee/e_sword.rsi, state: icon }
productEntity: EnergySword
cost:
Telecrystal: 8
Telecrystal: 10
categories:
- UplinkWeapons
@@ -1393,7 +1393,7 @@
description: uplink-mobcat-microbomb-desc
icon: { sprite: /Textures/Mobs/Pets/cat.rsi, state: syndicat }
productEntity: MobCatSyndy
cost:
cost:
Telecrystal: 10
categories:
- UplinkMisc

View File

@@ -157,7 +157,7 @@
- type: Store
preset: StorePresetUplink
balance:
Telecrystal: 0
Telecrystal: 10
- type: UserInterface
interfaces:
- key: enum.StoreUiKey.Key

View File

@@ -233,8 +233,8 @@
- type: IncreaseDamageOnWield
damage:
types:
Slash: 15
Heat: 13
Slash: 7.5
Heat: 7.5
- type: MeleeWeapon
attackRate: 1
- type: Reflect

View File

@@ -6,8 +6,8 @@
biomes:
- AsteroidsFallback
- Failsafe
- CombatRimAsteroidsStandard
- CombatRimAsteroidsWastes
#- CombatRimAsteroidsStandard
#- CombatRimAsteroidsWastes
- CombatRimAsteroidsEmptiness
- type: StructurePlacement
structures: