feat: Added conversion SqTable -> Dictionary

+ Added onBan event
+ Fixed wrong argument order in onTime event
This commit is contained in:
AURUMVORXX
2024-11-02 18:32:07 +03:00
parent 9361f00246
commit f5a748e1ff
5 changed files with 74 additions and 6 deletions

47
src/sqcontainers.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include <sqapi.h>
#include <pybind11/embed.h>
#include "sqcontainers.h"
namespace py = pybind11;
using namespace pybind11::literals;
py::dict sqParseTable(Sqrat::Table tab)
{
py::dict result;
Sqrat::Object::iterator tabIterator;
int i = 0;
while (tab.Next(tabIterator))
{
HSQOBJECT key = tabIterator.getKey();
HSQOBJECT value = tabIterator.getValue();
if (key._type != OT_STRING)
continue;
py::str pkey = "{0}_";
switch(value._type)
{
case OT_STRING:
// TODO: for some reason, key names 'name' and 'reason' crashing the server (maybe some more)
// Adding _ to key names is fixing this, but need to find a better solution
result[pkey.format(sq_objtostring(&key))] = sq_objtostring(&value);
break;
case OT_INTEGER:
result[sq_objtostring(&key)] = sq_objtointeger(&value);
break;
case OT_FLOAT:
result[sq_objtostring(&key)] = sq_objtofloat(&value);
break;
case OT_TABLE:
result[sq_objtostring(&key)] = sqParseTable(Sqrat::Table(value));
break;
default:
continue;
}
}
return result;
}