initial commit of auto command generator for xenforo post
This commit is contained in:
parent
40230f29c1
commit
0175616ae6
74
commands_list/python/main.py
Normal file
74
commands_list/python/main.py
Normal file
@ -0,0 +1,74 @@
|
||||
#!/home/nonroot/xenforo_list_commands/venv/bin/python3
|
||||
|
||||
from settings import (get_connection_racetimer, xenforo_api)
|
||||
import requests
|
||||
|
||||
|
||||
def get_all_ze_commands():
|
||||
with get_connection_racetimer() as conn:
|
||||
with conn.cursor(buffered=True) as cur:
|
||||
sql_statement = """
|
||||
select *
|
||||
from unloze_racetimer_css.ze_commands_info zci
|
||||
order by command asc
|
||||
"""
|
||||
cur.execute(sql_statement)
|
||||
res = cur.fetchall()
|
||||
conn.close()
|
||||
return res
|
||||
|
||||
def create_thread():
|
||||
headers = {
|
||||
'Content-type' : 'application/x-www-form-urlencoded',
|
||||
'XF-Api-User': '4',
|
||||
'XF-Api-Key' : xenforo_api
|
||||
}
|
||||
url_thread = "https://unloze.com/api/threads/"
|
||||
data = {
|
||||
'node_id': 74, # node ID is the forum ID, 74 should be ze
|
||||
'title': 'This is a test thread',
|
||||
'message': 'This is the thread message body contents. This is the thread message body contents.'
|
||||
}
|
||||
|
||||
r = requests.post(url_thread, headers=headers, data=data)
|
||||
print(r.status_code)
|
||||
|
||||
def edit_thread_post(res):
|
||||
headers = {
|
||||
'Content-type' : 'application/x-www-form-urlencoded',
|
||||
'XF-Api-User': '4',
|
||||
'XF-Api-Key' : xenforo_api
|
||||
}
|
||||
url_post_to_update = "https://unloze.com/api/posts/27293"
|
||||
msg = f"""
|
||||
This Thread serves the purpose of automatically listing all available commands on the zombie escape server that are available for normal players, vips and Admins. The Zombie Escape server currently has a total of {len(res)} Commands which are too many for any normal player or admin to remember. This thread hopefully serves the purpose of being a bookmark for finding all commands.\nSome commands like listmaps only work in console.\n\nThe thread will automatically be updated twice a day to include any new commands that are added on Zombie Escape. Use this thread as the ultimate commands reference (feedback is welcome ofc on how listing content should be done).\n\n"""
|
||||
msg_normal_commands = "[COLOR=rgb(184, 49, 47)][B][SIZE=8]Commands for normal players:[/SIZE][/B][/COLOR]\n\n"
|
||||
msg_vip_commands = "[COLOR=rgb(184, 49, 47)][B][SIZE=8]Commands for vips players:[/SIZE][/B][/COLOR]\n\n"
|
||||
msg_admin_commands = "[COLOR=rgb(184, 49, 47)][B][SIZE=8]Commands for admins:[/SIZE][/B][/COLOR]\n\n"
|
||||
|
||||
for result in res:
|
||||
command = result[0]
|
||||
description = result[1]
|
||||
flag = result[2]
|
||||
if flag == 'No flag registered':
|
||||
msg_normal_commands += f"{command} : {description}\n"
|
||||
elif flag == 'ADMFLAG_CUSTOM1 ' or flag == 'ADMFLAG_CUSTOM2' or flag == 'ADMFLAG_RESERVATION':
|
||||
msg_vip_commands += f"{command} : {description}\n"
|
||||
else:
|
||||
msg_admin_commands += f"{command} : {description}\n"
|
||||
msg += msg_normal_commands + "\n"
|
||||
msg += msg_vip_commands + "\n"
|
||||
msg += msg_admin_commands + "\n"
|
||||
data = {
|
||||
'message': msg
|
||||
}
|
||||
r = requests.post(url_post_to_update, headers=headers, data=data)
|
||||
print(r.status_code)
|
||||
|
||||
def main():
|
||||
res = get_all_ze_commands()
|
||||
#create_thread()
|
||||
edit_thread_post(res)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
120
commands_list/scripting/commands_info.sp
Normal file
120
commands_list/scripting/commands_info.sp
Normal file
@ -0,0 +1,120 @@
|
||||
#pragma semicolon 1
|
||||
#include <sourcemod>
|
||||
|
||||
Database g_hDatabase;
|
||||
|
||||
public Plugin myinfo ={
|
||||
name = "List SourceMod Command",
|
||||
author = "jenzur",
|
||||
description = "Lists SourceMod commands accessible to the client in a menu. just stolen from darthninja",
|
||||
version = "1.0",
|
||||
url = "https://forums.alliedmods.net/showthread.php?p=1524781"
|
||||
};
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
}
|
||||
else
|
||||
{
|
||||
Command_listcmd();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
g_hDatabase = db;
|
||||
Command_listcmd();
|
||||
}
|
||||
|
||||
public void Command_listcmd()
|
||||
{
|
||||
decl String:Command[64];
|
||||
decl String:Description[255];
|
||||
new Handle:hIterator = GetCommandIterator();
|
||||
|
||||
new iFlags;
|
||||
decl String:strFlags[64];
|
||||
|
||||
/* Start printing the commands to the client */
|
||||
while (ReadCommandIterator(hIterator, Command, sizeof(Command), iFlags, Description, sizeof(Description)))
|
||||
{
|
||||
Format(strFlags, sizeof(strFlags), "");
|
||||
|
||||
//This still may not be the best way to do this
|
||||
if (iFlags & ADMFLAG_RESERVATION)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_RESERVATION ");
|
||||
if (iFlags & ADMFLAG_GENERIC)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_GENERIC ");
|
||||
if (iFlags & ADMFLAG_KICK)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_KICK ");
|
||||
if (iFlags & ADMFLAG_BAN)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_BAN ");
|
||||
if (iFlags & ADMFLAG_UNBAN)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_UNBAN ");
|
||||
if (iFlags & ADMFLAG_SLAY)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_SLAY ");
|
||||
if (iFlags & ADMFLAG_CHANGEMAP)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CHANGEMAP ");
|
||||
if (iFlags & ADMFLAG_CONVARS)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CONVARS ");
|
||||
if (iFlags & ADMFLAG_CONFIG)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CONFIG ");
|
||||
if (iFlags & ADMFLAG_CHAT)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CHAT ");
|
||||
if (iFlags & ADMFLAG_VOTE)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_VOTE ");
|
||||
if (iFlags & ADMFLAG_PASSWORD)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_PASSWORD ");
|
||||
if (iFlags & ADMFLAG_RCON)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_RCON ");
|
||||
if (iFlags & ADMFLAG_CHEATS)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CHEATS ");
|
||||
if (iFlags & ADMFLAG_ROOT)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_ROOT ");
|
||||
if (iFlags & ADMFLAG_CUSTOM1)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM1 ");
|
||||
if (iFlags & ADMFLAG_CUSTOM2)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM2 ");
|
||||
if (iFlags & ADMFLAG_CUSTOM3)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM3 ");
|
||||
if (iFlags & ADMFLAG_CUSTOM4)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM4 ");
|
||||
if (iFlags & ADMFLAG_CUSTOM5)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM5 ");
|
||||
if (iFlags & ADMFLAG_CUSTOM6)
|
||||
StrCat(strFlags, sizeof(strFlags), "ADMFLAG_CUSTOM6 ");
|
||||
if (iFlags == 0)
|
||||
Format(strFlags, sizeof(strFlags), "No flag registered");
|
||||
|
||||
if (StrEqual(Description, "", false))
|
||||
Format(Description, sizeof(Description), "No description found");
|
||||
//PrintToChatAll("Command: %s Description: %s strFlags: %s", Command, Description, strFlags);
|
||||
char sQuery[512];
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `ze_commands_info` (`command`, `description`, `flag`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `description` = '%s', `flag` = '%s'", Command, Description, strFlags, Description, strFlags);
|
||||
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, DBPrio_Low);
|
||||
}
|
||||
CloseHandle(hIterator);
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
delete results;
|
||||
}
|
||||
delete data;
|
||||
}
|
10
commands_list/systemctl/commands_list.service
Normal file
10
commands_list/systemctl/commands_list.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=runs command list posting to xenforo forum
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=nonroot
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
Environment=PATH=/home/nonroot/xenforo_list_commands/venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
|
||||
WorkingDirectory=/home/nonroot/xenforo_list_commands
|
||||
ExecStart=/home/nonroot/xenforo_list_commands/main.py
|
9
commands_list/systemctl/commands_list.timer
Normal file
9
commands_list/systemctl/commands_list.timer
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Decides when to update the forum post about commands
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 04:00:00
|
||||
OnCalendar=*-*-* 20:00:00
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user