This repository was archived by the owner on Mar 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_scp.cs
More file actions
109 lines (100 loc) · 4.27 KB
/
Commands_scp.cs
File metadata and controls
109 lines (100 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Linq;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using Firestar4.ScpListSharp;
using Firestar4.ScpListSharp.Entities;
using Firestar4.ScpBanInfo;
using DiscordUrie_DSharpPlus.Attributes;
namespace DiscordUrie_DSharpPlus
{
public partial class Commands : ApplicationCommandModule
{
[SlashCommand("scp", "Gets Packing Peanut's server info")]
public async Task Scp(InteractionContext ctx)
{
SCPServer TargetServer;
DiscordInteractionResponseBuilder MessageBuilder = new DiscordInteractionResponseBuilder();
try
{
var ServerList = await Rest.GetOwnServersAsync(discordUrie.BootConfig.ScpID, discordUrie.BootConfig.ScpKey, Players: true, Info: true, Version: true, Online: true);
discordUrie.CachedServerInfo = ServerList;
discordUrie.CacheTimestamp = DateTime.Now;
TargetServer = ServerList.First();
}
catch (Exception ex)
{
if (discordUrie.CachedServerInfo.Count == 0)
{
await ctx.CreateResponseAsync(ex.Message);
return;
}
TargetServer = discordUrie.CachedServerInfo.First();
MessageBuilder.WithContent($"Rate limited, displaying cached info from {Formatter.Timestamp(discordUrie.CacheTimestamp)}");
}
var FixedInfo = Regex.Replace(TargetServer.Info, "<[^>]+>", "");
DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
builder.Title = FixedInfo;
builder.WithColor(new DiscordColor("#00ffff"));
builder.AddField("Online", TargetServer.Online.ToString());
builder.AddField("Players", TargetServer.Players);
builder.AddField("Friendly fire", TargetServer.FF.ToString());
builder.AddField("Version", TargetServer.Version);
builder.AddField("Modded", TargetServer.Modded.ToString());
MessageBuilder.AddEmbed(builder.Build());
await ctx.CreateResponseAsync(MessageBuilder);
}
[SlashCommandGroup("scpbans", "Search for a ban on the scp server"), RequireAuth]
public class Scpbans : ApplicationCommandModule
{
public DiscordUrie discordUrie { get; set; }
public Scpbans(DiscordUrie du)
{
discordUrie = du;
}
[SlashCommand("get", "Search for a ban on the scp server")]
public async Task ScpBans(InteractionContext ctx, [Option("search", "The string to search by. Searches for the name, id, or ban reason.")] string search, [Option("DisplayAdminInfo", "Whether or not to display the admin's info.")] bool DisplayAdminInfo = true)
{
await ctx.DeferAsync();
var data = await ScpBanInfo.GetData();
string lower = search.ToLower();
var pop = data.FindAll(xr => lower == xr.Target.Name.ToLower() || search == xr.Target.ID.ToString() || lower == xr.Reason.ToLower());
if (pop.Count == 0)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("No matches found."));
return;
}
var peep = pop.First();
var reason = peep.Reason;
if (String.IsNullOrEmpty(reason))
reason = "No ban reason givin.";
DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
builder.Title = $"Ban info for: {peep.Target.Name}";
builder.Description = $"ID: {peep.Target.ID.ToString()}";
builder.AddField("Reason", reason);
if (DisplayAdminInfo)
builder.AddField("Admin name", peep.AdminName);
builder.AddField("Ban time", peep.BanTime.ToShortDateString());
builder.AddField("Unban time", peep.UnbanTime.ToShortDateString());
builder.AddField("Ban duration", (peep.BanTime - peep.UnbanTime).ToString("%d' day(s), '%h' hour(s), '%m' minutes, '%s' second(s)'"));
await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(builder));
}
[SlashCommand("list", "List all bans")]
public async Task ListBans(InteractionContext ctx)
{
var data = await ScpBanInfo.GetData();
InteractivityExtension intex = ctx.Client.GetInteractivity();
if (data.Count <= 0) return;
IEnumerable<string> TagKeys = data.Select(xr => $"{xr.Target.Name} | {xr.Target.ID}");
string EditedTags = String.Join("\n", TagKeys);
await intex.SendPaginatedResponseAsync(ctx.Interaction, false, ctx.User, intex.GeneratePagesInEmbed(EditedTags, DSharpPlus.Interactivity.Enums.SplitType.Line));
}
}
}
}