Initial commit

This commit is contained in:
2025-04-15 22:27:20 -04:00
parent 5b7b68f81f
commit 771d8fe8e8
597 changed files with 149544 additions and 0 deletions

View File

@@ -0,0 +1,209 @@
#pragma semicolon 1
#define PLUGIN_VERSION "1.10"
#include <sourcemod>
#include <discord>
#define BOT_TOKEN ""
#define WEBHOOK ""
public Plugin myinfo =
{
name = "Discord Test",
author = "Deathknife",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot;
public void OnPluginStart() {
RegConsoleCmd("sm_getguilds", Cmd_GetGuilds);
RegConsoleCmd("sm_recreatebot", Cmd_RecreateBot);
RegConsoleCmd("sm_webhooktest", Cmd_Webhook);
RegConsoleCmd("sm_sendmsg", Cmd_SendMsg);
RegConsoleCmd("sm_getroles", Cmd_GetRoles);
}
public void OnAllPluginsLoaded() {
gBot = new DiscordBot(BOT_TOKEN);
}
public Action Cmd_Webhook(int client, int argc) {
DiscordWebHook hook = new DiscordWebHook(WEBHOOK);
hook.SlackMode = true;
hook.SetContent("@here");
hook.SetUsername("Server");
MessageEmbed Embed = new MessageEmbed();
Embed.SetColor("#ff2222");
Embed.SetTitle("Testing WebHook");
Embed.AddField("Field1", "Test1", true);
Embed.AddField("abc def", "deef", true);
hook.Embed(Embed);
hook.Send();
delete hook;
hook = new DiscordWebHook("");
hook.SetUsername("Testing");
hook.SlackMode = false;
hook.SetContent("Testing 1 2 3");
hook.Send();
delete hook;
}
public Action Cmd_GetRoles(int client, int argc) {
if(client == 0)
{
ReplyToCommand(client, "[SM] This command cannot be used from console.");
return Plugin_Handled;
}
gBot.GetGuilds(GuildListGetRoles, _, GetClientUserId(client));
ReplyToCommand(client, "Trying!");
return Plugin_Handled;
}
public void GuildListGetRoles(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
bot.GetGuildRoles(id, OnGetRoles, data);
}
}
public void OnGetRoles(DiscordBot bot, char[] guild, RoleList roles, any data) {
PrintToChatAll("%i a", data);
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
PrintToConsole(client, "Roles for guild %s", guild);
for(int i = 0; i < roles.Size; i++) {
Role role = roles.Get(i);
char id[64];
char name[64];
role.GetID(id, sizeof(id));
role.GetName(name, sizeof(name));
PrintToConsole(client, "Role %s %s", id, name);
}
}
}
public Action Cmd_GetGuilds(int client, int argc) {
if(client == 0)
{
ReplyToCommand(client, "[SM] This command cannot be used from console.");
return Plugin_Handled;
}
gBot.GetGuilds(GuildList, GuildListAll, GetClientUserId(client));
ReplyToCommand(client, "Trying!");
return Plugin_Handled;
}
public Action Cmd_RecreateBot(int client, int argc) {
if(gBot != null) {
gBot.StopListening();
delete gBot;
}
gBot = new DiscordBot(BOT_TOKEN);
ReplyToCommand(client, "Recreated");
}
public void GuildList(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
PrintToConsole(client, "Guild [%s] [%s] [%s] [%i] [%i]", id, name, icon, owner, permissions);
gBot.GetGuildChannels(id, ChannelList, INVALID_FUNCTION, data);
}
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
char name[32];
char id[32];
Channel.GetID(id, sizeof(id));
Channel.GetName(name, sizeof(name));
PrintToConsole(client, "Channel for Guild(%s) - [%s] [%s]", guild, id, name);
if(Channel.IsText) {
//Send a message with all ways
//gBot.SendMessage(Channel, "Sending message with DiscordBot.SendMessage");
//gBot.SendMessageToChannelID(id, "Sending message with DiscordBot.SendMessageToChannelID");
//Channel.SendMessage(gBot, "Sending message with DiscordChannel.SendMessage");
gBot.StartListeningToChannel(Channel, OnMessage);
}
}
}
public void OnMessage(DiscordBot Bot, DiscordChannel Channel, DiscordMessage message) {
char sMessage[2048];
message.GetContent(sMessage, sizeof(sMessage));
char sAuthor[128];
message.GetAuthor().GetUsername(sAuthor, sizeof(sAuthor));
PrintToChatAll("[DISCORD] %s: %s", sAuthor, sMessage);
if(StrEqual(sMessage, "Ping", false)) {
gBot.SendMessage(Channel, "Pong!");
}
}
public void GuildListAll(DiscordBot bot, ArrayList Alid, ArrayList Alname, ArrayList Alicon, ArrayList Alowner, ArrayList Alpermissions, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
char id[32];
char name[64];
char icon[128];
bool owner;
int permissions;
PrintToConsole(client, "Dumping Guilds from arraylist");
for(int i = 0; i < Alid.Length; i++) {
GetArrayString(Alid, i, id, sizeof(id));
GetArrayString(Alname, i, name, sizeof(name));
GetArrayString(Alicon, i, icon, sizeof(icon));
owner = GetArrayCell(Alowner, i);
permissions = GetArrayCell(Alpermissions, i);
PrintToConsole(client, "Guild: [%s] [%s] [%s] [%i] [%i]", id, name, icon, owner, permissions);
}
}
}
public Action Cmd_SendMsg(int client, int argc) {
if(client == 0)
{
ReplyToCommand(client, "[SM] This command cannot be used from console.");
return Plugin_Handled;
}
if(argc != 2)
{
ReplyToCommand(client, "[SM] Usage: sm_sendmsg <channelid> <message>.");
return Plugin_Handled;
}
char channelid[64];
GetCmdArg(1, channelid, sizeof(channelid));
char message[256];
GetCmdArg(2, message, sizeof(message));
gBot.SendMessageToChannelID(channelid, message, OnMessageSent, GetClientUserId(client));
return Plugin_Handled;
}
public void OnMessageSent(DiscordBot bot, char[] channel, DiscordMessage message, any data)
{
int client = GetClientOfUserId(data);
ReplyToCommand(client, "Message sent!");
}

View File

@@ -0,0 +1,14 @@
# discord_test.sp
On the command: `sm_getguilds` / `!getguilds` the plugin will list all guilds and channels in the client console. It will hook into every channel and print any messages in discord channel to the server console. If the message is `Ping` it will reply with `Pong`. `sm_recreatebot` will delete the bot and create it again(for testing purposes)
Not recommended to use this plugin on live server.
# discord_announcement.sp
The plugin will hook into any channels with the name of `server-announcement` and print any messages sent in that channel to all players on servers with the `[Announcement]` prefix.
Should be fine to have this on a live server.
# discord_calladmin.sp
The plugin finds all channels with the name of `call-admin` and stores them. When a client types `!calladmin` it will send a message to all those channels.
Should be fine to have this on a live server.

View File

@@ -0,0 +1,57 @@
#pragma semicolon 1
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <csgocolors>
#include <discord>
public Plugin myinfo = {
name = "Announcements from Discord",
author = "Deathknife",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot = null;
public void OnPluginStart() {
//
}
public OnAllPluginsLoaded() {
//Create bot with a token
gBot = new DiscordBot("<Bot Token>");
//Check for messages every 5 seconds. Default is 1 second. Since this is announcement, time accuracy is not necessary
gBot.MessageCheckInterval = 5.0;
//Get all guilds then channels to find any channel with the name of server-announcement
gBot.GetGuilds(GuildList);
}
public void GuildList(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
//Retrieve all channels for the guild
bot.GetGuildChannels(id, ChannelList);
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
//Verify that the channel is a text channel
if(Channel.IsText) {
//Get name of channel
char name[32];
Channel.GetName(name, sizeof(name));
//Compare name of channel to 'server-announcement'
if(StrEqual(name, "server-announcement", false)) {
//Start listening to channel
bot.StartListeningToChannel(Channel, OnMessage);
}
}
}
public void OnMessage(DiscordBot Bot, DiscordChannel Channel, const char[] message) {
//Received a message, print it out.
CPrintToChatAll("{green}[Announcement]{normal} %s", message);
}

View File

@@ -0,0 +1,119 @@
#pragma semicolon 1
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <csgocolors>
#include <discord>
#include <SteamWorks>
public Plugin myinfo = {
name = "Call Admin to Discord",
author = "Deathknife",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot = null;
ArrayList CallAdminChannels = null;
ConVar gHostPort;
ConVar gHostname;
//To prevent spam
int LastUsage[MAXPLAYERS + 1];
public void OnPluginStart() {
RegConsoleCmd("sm_calladmin", Cmd_CallAdmin);
CallAdminChannels = new ArrayList();
gHostname = FindConVar("hostname");
gHostPort = FindConVar("hostport");
}
public OnAllPluginsLoaded() {
//Create bot with a token
gBot = new DiscordBot("<Bot Token>");
//Get all guilds then channels to find any channel with the name of call-admin
gBot.GetGuilds(GuildList);
}
public Action Cmd_CallAdmin(int client, int argc) {
//Add minimum 60 seconds interval before calling an admin again
if(GetTime() < LastUsage[client] + 60) {
CReplyToCommand(client, "{red}Please wait before calling an admin again!");
return Plugin_Continue;
}
//Format Message to send
char message[256];
char name[32];
GetClientName(client, name, sizeof(name));
//Replace ` with nothing as we will use `NAME` in discord message
ReplaceString(name, sizeof(name), "`", "");
char authid[32];
GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
char ip[64];
GetIP(ip, sizeof(ip));
char hostname[64];
GetConVarString(gHostname, hostname, sizeof(hostname));
FormatEx(message, sizeof(message), "`%s` (`%s`) has called an Admin on %s\nConnect: steam://connect/%s", name, authid, hostname, ip);
//Send Message to all channels we stored
for(int i = 0; i < CallAdminChannels.Length; i++) {
DiscordChannel Channel = CallAdminChannels.Get(i);
Channel.SendMessage(gBot, message);
}
CReplyToCommand(client, "{green}Called an Admin");
LastUsage[client] = GetTime();
return Plugin_Continue;
}
public void OnClientPutInServer(int client) {
LastUsage[client] = 0;
}
public void GuildList(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
//Retrieve all channels for the guild
//PrintToServer("Guild %s", name);
bot.GetGuildChannels(id, ChannelList);
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
//Verify that the channel is a text channel
if(Channel.IsText) {
//Get name of channel
char name[32];
Channel.GetName(name, sizeof(name));
//PrintToServer("Channel name %s", name);
//Compare name of channel to 'call-admin'
if(StrEqual(name, "call-admin", false)) {
PrintToServer("Added Call Admin Channel");
//Store The Channel
//Duplicate the Channel handle as the 'Channel' handle is closed after the forwards are called
DiscordChannel newChannel = view_as<DiscordChannel>(CloneHandle(Channel));
//Store it into array
CallAdminChannels.Push(newChannel);
}
}
}
//Stores IP into buffer using SteamWorks
stock void GetIP(char[] buffer, int maxlength) {
int ip[4];
SteamWorks_GetPublicIP(ip);
strcopy(buffer, maxlength, "");
FormatEx(buffer, maxlength, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], gHostPort.IntValue);
}

View File

@@ -0,0 +1,135 @@
#pragma semicolon 1
#define PLUGIN_VERSION "1.10"
#include <sourcemod>
#include <discord>
#define BOT_TOKEN "INSERT TOKEN HERE"
public Plugin myinfo =
{
name = "Discord Test",
author = "Deathknife",
description = "",
version = PLUGIN_VERSION,
url = ""
};
DiscordBot gBot;
public void OnPluginStart() {
RegConsoleCmd("sm_getguilds", Cmd_GetGuilds);
RegConsoleCmd("sm_recreatebot", Cmd_RecreateBot);
RegConsoleCmd("sm_webhooktest", Cmd_Webhook);
}
public void OnPluginEnd() {
if(gBot != null) {
gBot.DestroyData();
delete gBot;
}
}
public void OnAllPluginsLoaded() {
gBot = new DiscordBot(BOT_TOKEN);
}
public Action Cmd_Webhook(int client, int argc) {
DiscordWebHook hook = new DiscordWebHook("https://ptb.discordapp.com/api/webhooks/265660968086929419/z3_F8CEGNu1Wtdygv4v0Pg4YRBA8QxgmzFKqjkEleSf2BOuQ8Xz7Ub05ku2j-O2vofy7");
hook.SlackMode = true;
hook.SetUsername("Server");
hook.SetColor("#ff2222");
hook.SetTitle("Testing WebHook");
hook.SetContent("@here");
hook.AddField("Field1", "Test1", true);
hook.AddField("abc def", "deef", true);
hook.Send();
delete hook;
hook = new DiscordWebHook("https://ptb.discordapp.com/api/webhooks/265660968086929419/z3_F8CEGNu1Wtdygv4v0Pg4YRBA8QxgmzFKqjkEleSf2BOuQ8Xz7Ub05ku2j-O2vofy7");
hook.SetUsername("Testing");
hook.SlackMode = false;
hook.SetContent("Testing 1 2 3");
hook.Send();
delete hook;
}
public Action Cmd_GetGuilds(int client, int argc) {
gBot.GetGuilds(GuildList, GuildListAll, GetClientUserId(client));
ReplyToCommand(client, "Trying!");
return Plugin_Handled;
}
public Action Cmd_RecreateBot(int client, int argc) {
if(gBot != null) {
gBot.DestroyData();
delete gBot;
}
gBot = new DiscordBot(BOT_TOKEN);
ReplyToCommand(client, "Recreated");
}
public void GuildList(DiscordBot bot, char[] id, char[] name, char[] icon, bool owner, int permissions, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
PrintToConsole(client, "Guild [%s] [%s] [%s] [%i] [%i]", id, name, icon, owner, permissions);
gBot.GetGuildChannels(id, ChannelList, INVALID_FUNCTION, data);
}
}
public void ChannelList(DiscordBot bot, char[] guild, DiscordChannel Channel, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
char name[32];
char id[32];
Channel.GetID(id, sizeof(id));
Channel.GetName(name, sizeof(name));
PrintToConsole(client, "Channel for Guild(%s) - [%s] [%s]", guild, id, name);
if(Channel.IsText) {
//Send a message with all ways
gBot.SendMessage(Channel, "Sending message with DiscordBot.SendMessage");
gBot.SendMessageToChannelID(id, "Sending message with DiscordBot.SendMessageToChannelID");
Channel.SendMessage(gBot, "Sending message with DiscordChannel.SendMessage");
gBot.StartListeningToChannel(Channel, OnMessage);
}
}
}
public void OnMessage(DiscordBot Bot, DiscordChannel Channel, const char[] message) {
PrintToServer("Message from discord: %s", message);
if(StrEqual(message, "Ping", false)) {
gBot.SendMessage(Channel, "Pong!");
}
}
public void GuildListAll(DiscordBot bot, ArrayList Alid, ArrayList Alname, ArrayList Alicon, ArrayList Alowner, ArrayList Alpermissions, any data) {
int client = GetClientOfUserId(data);
if(client > 0 && IsClientConnected(client) && IsClientInGame(client)) {
char id[32];
char name[64];
char icon[128];
bool owner;
int permissions;
PrintToConsole(client, "Dumping Guilds from arraylist");
for(int i = 0; i < Alid.Length; i++) {
GetArrayString(Alid, i, id, sizeof(id));
GetArrayString(Alname, i, name, sizeof(name));
GetArrayString(Alicon, i, icon, sizeof(icon));
owner = GetArrayCell(Alowner, i);
permissions = GetArrayCell(Alpermissions, i);
PrintToConsole(client, "Guild: [%s] [%s] [%s] [%i] [%i]", id, name, icon, owner, permissions);
}
}
}
public Action Cmd_SendMsg(int client, int argc) {
//
}