Skip to content

Commit

Permalink
Add summon command to Discord-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokilife committed Feb 18, 2024
1 parent c83f18f commit eb9a9f5
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Content.Server.Database;
using Discord;
using Discord.Interactions;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;

namespace Content.DiscordBot;

public sealed partial class VerificationModule : InteractionModuleBase<SocketInteractionContext>
public sealed partial class UsersModule : InteractionModuleBase<SocketInteractionContext>
{
[Dependency] private readonly IServerDbManager _db = default!;
public static readonly ISawmill Log = LogHelper.GetLogger("discord.interaction_handling");
public static readonly ISawmill Log = LogHelper.GetLogger("discord.users_module");

public override void BeforeExecute(ICommandInfo command)
{
DiscordIoC.InjectDependencies(this);
}

[SlashCommand("verify", "Проверифицируйте свой аккаунт")]
[SlashCommand("привязать", "Привяжите свой аккаунт Discord к аккаунту SS14")]
[RequireContext(ContextType.Guild)]
public async Task VerifyCommand(string verificationCode)
{
Expand All @@ -31,4 +32,26 @@ public async Task VerifyCommand(string verificationCode)
await _db.LinkDiscord(new NetUserId((Guid) player), Context.User.Id);
await RespondAsync("Ваш аккаунт Discord успешно привязан!");
}

[SlashCommand("призвать", "Призовите игрока")]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.MentionEveryone)]
public async Task SummonCommand(string ckey)
{
var player = await _db.GetPlayerRecordByUserName(ckey);

if (player == null)
{
await RespondAsync("❗ Пользователя с таким CKey не существует в нашей базе данных");
return;
}

if (player.DiscordId == null)
{
await RespondAsync("❗ У данного пользователя отсутствует привязанный профиль Discord");
return;
}

await RespondAsync($"👉 <@!{player.DiscordId}>");
}
}

0 comments on commit eb9a9f5

Please sign in to comment.