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); _controller.UpdateSelectedChannel(this);
// Warn typing indicator about change // 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) protected override void Dispose(bool disposing)

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Afk; using Content.Server.Afk;
using Content.Server.Afk.Events; using Content.Server.Afk.Events;
using Content.Server.GameTicking; using Content.Server.GameTicking;
@@ -31,6 +32,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly MindSystem _minds = default!; [Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly PlayTimeTrackingManager _tracking = default!; [Dependency] private readonly PlayTimeTrackingManager _tracking = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -157,8 +159,16 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
_tracking.QueueSendTimers(ev.PlayerSession); _tracking.QueueSendTimers(ev.PlayerSession);
} }
private bool IsBypassingChecks(ICommonSession player)
{
return _adminManager.IsAdmin(player, true);
}
public bool IsAllowed(ICommonSession player, string role) public bool IsAllowed(ICommonSession player, string role)
{ {
if (IsBypassingChecks(player))
return true;
if (!_prototypes.TryIndex<JobPrototype>(role, out var job) || if (!_prototypes.TryIndex<JobPrototype>(role, out var job) ||
job.Requirements == null || job.Requirements == null ||
!_cfg.GetCVar(CCVars.GameRoleTimers)) !_cfg.GetCVar(CCVars.GameRoleTimers))
@@ -172,6 +182,10 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
public HashSet<string> GetDisallowedJobs(ICommonSession player) public HashSet<string> GetDisallowedJobs(ICommonSession player)
{ {
var roles = new HashSet<string>(); var roles = new HashSet<string>();
if (IsBypassingChecks(player))
return roles;
if (!_cfg.GetCVar(CCVars.GameRoleTimers)) if (!_cfg.GetCVar(CCVars.GameRoleTimers))
return roles; return roles;
@@ -203,6 +217,10 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
return; return;
var player = _playerManager.GetSessionByUserId(userId); var player = _playerManager.GetSessionByUserId(userId);
if (IsBypassingChecks(player))
return;
if (!_tracking.TryGetTrackerTimes(player, out var playTimes)) if (!_tracking.TryGetTrackerTimes(player, out var playTimes))
{ {
// Sorry mate but your playtimes haven't loaded. // 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.Server.Maps;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Content.Shared.White; using Content.Shared.White;
using Robust.Shared;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
namespace Content.Server.Corvax.RoundNotifications; namespace Content.Server.White.Discord;
/// <summary> /// <summary>
/// Listen game events and send notifications to Discord /// Listen game events and send notifications to Discord
@@ -20,10 +21,14 @@ public sealed class RoundNotificationsSystem : EntitySystem
private ISawmill _sawmill = default!; private ISawmill _sawmill = default!;
private readonly HttpClient _httpClient = new(); private readonly HttpClient _httpClient = new();
private string _webhookUrl = String.Empty; private string _webhookUrl = string.Empty;
private string _roleId = String.Empty; private string _roleId = string.Empty;
private string _serverName = string.Empty;
private bool _roundStartOnly; private bool _roundStartOnly;
private const int EmbedColor = 0x6600FF;
private const int EmbedColorRestart = 0x00eb1f;
/// <inheritdoc/> /// <inheritdoc/>
public override void Initialize() public override void Initialize()
{ {
@@ -34,29 +39,36 @@ public sealed class RoundNotificationsSystem : EntitySystem
_config.OnValueChanged(WhiteCVars.DiscordRoundWebhook, value => _webhookUrl = value, true); _config.OnValueChanged(WhiteCVars.DiscordRoundWebhook, value => _webhookUrl = value, true);
_config.OnValueChanged(WhiteCVars.DiscordRoundRoleId, value => _roleId = value, true); _config.OnValueChanged(WhiteCVars.DiscordRoundRoleId, value => _roleId = value, true);
_config.OnValueChanged(WhiteCVars.DiscordRoundStartOnly, value => _roundStartOnly = value, true); _config.OnValueChanged(WhiteCVars.DiscordRoundStartOnly, value => _roundStartOnly = value, true);
_config.OnValueChanged(CVars.GameHostName, value => _serverName = value, true);
_sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("notifications"); _sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("notifications");
} }
private void OnRoundRestart(RoundRestartCleanupEvent e) private void OnRoundRestart(RoundRestartCleanupEvent e)
{ {
if (String.IsNullOrEmpty(_webhookUrl)) if (string.IsNullOrEmpty(_webhookUrl))
return; return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var payload = new WebhookPayload() 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")}", { "roles", new[] { _roleId } }
AllowedMentions = new Dictionary<string, string[]>
{
{ "roles", new []{ _roleId } }
},
}; };
} }
@@ -65,30 +77,56 @@ public sealed class RoundNotificationsSystem : EntitySystem
private void OnRoundStarted(RoundStartedEvent e) private void OnRoundStarted(RoundStartedEvent e)
{ {
if (String.IsNullOrEmpty(_webhookUrl)) if (string.IsNullOrEmpty(_webhookUrl))
return; return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var map = _gameMapManager.GetSelectedMap(); var map = _gameMapManager.GetSelectedMap();
var mapName = map?.MapName ?? Loc.GetString("discord-round-unknown-map"); var mapName = map?.MapName ?? Loc.GetString("discord-round-unknown-map");
var text = Loc.GetString("discord-round-start", var text = Loc.GetString("discord-round-start",
("id", e.RoundId), ("id", e.RoundId),
("map", mapName)); ("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); SendDiscordMessage(payload);
} }
private void OnRoundEnded(RoundEndedEvent e) private void OnRoundEnded(RoundEndedEvent e)
{ {
if (String.IsNullOrEmpty(_webhookUrl) || _roundStartOnly) if (string.IsNullOrEmpty(_webhookUrl) || _roundStartOnly)
return; return;
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
var text = Loc.GetString("discord-round-end", var text = Loc.GetString("discord-round-end",
("id", e.RoundId), ("id", e.RoundId),
("hours", e.RoundDuration.Hours), ("hours", e.RoundDuration.Hours),
("minutes", e.RoundDuration.Minutes), ("minutes", e.RoundDuration.Minutes),
("seconds", e.RoundDuration.Seconds)); ("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); SendDiscordMessage(payload);
} }
@@ -101,8 +139,8 @@ public sealed class RoundNotificationsSystem : EntitySystem
var content = await request.Content.ReadAsStringAsync(); var content = await request.Content.ReadAsStringAsync();
if (!request.IsSuccessStatusCode) if (!request.IsSuccessStatusCode)
{ {
_sawmill.Log(LogLevel.Error, $"Discord returned bad status code when posting message: {request.StatusCode}\nResponse: {content}"); _sawmill.Log(LogLevel.Error,
return; $"Discord returned bad status code when posting message: {request.StatusCode}\nResponse: {content}");
} }
} }
@@ -111,6 +149,9 @@ public sealed class RoundNotificationsSystem : EntitySystem
[JsonPropertyName("content")] [JsonPropertyName("content")]
public string Content { get; set; } = ""; public string Content { get; set; } = "";
[JsonPropertyName("embeds")]
public List<Embed>? Embeds { get; init; } = null;
[JsonPropertyName("allowed_mentions")] [JsonPropertyName("allowed_mentions")]
public Dictionary<string, string[]> AllowedMentions { get; set; } = public Dictionary<string, string[]> AllowedMentions { get; set; } =
new() 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-embed-title = SS14 | { $server }
discord-round-start = Раунд #{ $id } на карте "{ $map }" начался. discord-round-new = Новый раунд начинается!
discord-round-end = Раунд #{ $id } закончился. Он длился { $hours } ч., { $minutes } мин., и { $seconds } сек. discord-round-start = Раунд **#{ $id }** на карте **"{ $map }"** начался.
discord-round-end = Раунд **#{ $id }** закончился. Он длился **{ $hours } ч., { $minutes } мин., и { $seconds } сек.**
discord-round-unknown-map = Неизвестна 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 } icon: { sprite: /Textures/Objects/Weapons/Melee/e_sword.rsi, state: icon }
productEntity: EnergySword productEntity: EnergySword
cost: cost:
Telecrystal: 8 Telecrystal: 10
categories: categories:
- UplinkWeapons - UplinkWeapons

View File

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

View File

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

View File

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