more work on lua module

This commit is contained in:
Aaron Blakely 2024-03-02 02:11:50 -06:00
parent f91fac4d1e
commit d7b82df673
5 changed files with 120 additions and 0 deletions

View File

@ -58,6 +58,7 @@ MY_API void irc_part(struct irc_conn *bot, char *channel, char *reason);
MY_API void irc_ban(struct irc_conn *bot, char *channel, char *nick);
MY_API void irc_kick(struct irc_conn *bot, char *channel, char *user, char *reason);
MY_API void irc_mode(struct irc_conn *bot, char *channel, char *mode);
MY_API void irc_ctcp(struct irc_conn *bot, char *to, char *fmt, ...);
void irc_parse_raw(struct irc_conn *bot, char *raw);

36
mods/lua/README.md Executable file
View File

@ -0,0 +1,36 @@
# API
## Lua Commands
### `raw`(`message`: string)
Sends a raw message to the server.
### `privmsg`(`to`: string, `message`: string)
Sends a message to a channel or user.
### `notice`(`to`: string, `message`: string)
Sends a notice to a channel or user.
### `join`(`channel`: string)
Joins a channel.
### `part`(`channel`: string)
Leaves a channel.
### `kick`(`channel`: string, `user`: string, `reason`: string)
Kicks a user from a channel. Reason is optional.
### `mode`(`channel`: string, `mode`: string, `target`: string)
Sets a mode on a channel.
### `ctcp`(`to`: string, `message`: string)
Sends a CTCP message to a channel or user.

View File

@ -63,6 +63,13 @@ void lua_fire_handlers(char *event, ...);
void lua_init_wrappers();
void raw_wrapper(lua_State *L);
void privmsg_wrapper(lua_State *L);
void notice_wrapper(lua_State *L);
void join_wrapper(lua_State *L);
void part_wrapper(lua_State *L);
void ban_wrapper(lua_State *L);
void kick_wrapper(lua_State *L);
void mode_wrapper(lua_State *L);
void ctcp_wrapper(lua_State *L);
// handlers.c
void lua_init_handlers();

View File

@ -3,3 +3,5 @@ cl /I "..\..\lib" /I "..\..\include\libconfig-1.7.3\lib" /I "..\..\include\lua5.
cl /I "..\..\lib" /I "..\..\include\libconfig-1.7.3\lib" /I "..\..\include\lua5.3\include" /c wrappers.c
cl /I "..\..\lib" /I "..\..\include\libconfig-1.7.3\lib" /I "..\..\include\lua5.3\include" /c lua.c
link /DLL /out:..\lua.dll events.obj handlers.obj wrappers.obj lua.obj ..\..\Debug\xbot.lib ..\..\include\libconfig.lib ..\..\include\lua5.3\lua53.lib
del *.obj

View File

@ -4,6 +4,13 @@ void lua_init_wrappers()
{
lua_register(lua.L, "raw", raw_wrapper);
lua_register(lua.L, "privmsg", privmsg_wrapper);
lua_register(lua.L, "notice", notice_wrapper);
lua_register(lua.L, "join", join_wrapper);
lua_register(lua.L, "part", part_wrapper);
lua_register(lua.L, "ban", ban_wrapper);
lua_register(lua.L, "kick", kick_wrapper);
lua_register(lua.L, "mode", mode_wrapper);
lua_register(lua.L, "ctcp", ctcp_wrapper);
}
void raw_wrapper(lua_State *L)
@ -20,3 +27,70 @@ void privmsg_wrapper(lua_State *L)
irc_privmsg(instance, where, text);
}
void notice_wrapper(lua_State *L)
{
char *where = (char *)lua_tostring(L, 1);
char *text = (char *)lua_tostring(L, 2);
irc_notice(instance, where, text);
}
void join_wrapper(lua_State *L)
{
char *chan = (char *)lua_tostring(L, 1);
irc_join(instance, chan);
}
void part_wrapper(lua_State *L)
{
char *chan = (char *)lua_tostring(L, 1);
char *reason = (char *)lua_tostring(L, 2);
if (!reason)
{
reason = "";
}
irc_part(instance, chan, reason);
}
void ban_wrapper(lua_State *L)
{
char *chan = (char *)lua_tostring(L, 1);
char *user = (char *)lua_tostring(L, 2);
irc_ban(instance, chan, user);
}
void kick_wrapper(lua_State *L)
{
char *chan = (char *)lua_tostring(L, 1);
char *user = (char *)lua_tostring(L, 2);
char *reason = (char *)lua_tostring(L, 3);
if (!reason)
{
reason = "";
}
irc_kick(instance, chan, user, reason);
}
void mode_wrapper(lua_State *L)
{
char *chan = (char *)lua_tostring(L, 1);
char *mode = (char *)lua_tostring(L, 2);
irc_mode(instance, chan, mode);
}
void ctcp_wrapper(lua_State *L)
{
char *to = (char *)lua_tostring(L, 1);
char *msg = (char *)lua_tostring(L, 2);
va_list ap;
irc_ctcp(instance, to, msg);
}