diff --git a/lib/irc.h b/lib/irc.h index 7a2989a..f4c44cb 100755 --- a/lib/irc.h +++ b/lib/irc.h @@ -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); diff --git a/mods/lua/README.md b/mods/lua/README.md new file mode 100755 index 0000000..c08d07c --- /dev/null +++ b/mods/lua/README.md @@ -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. + diff --git a/mods/lua/lua.h b/mods/lua/lua.h index 1ce66c6..818fb9b 100755 --- a/mods/lua/lua.h +++ b/mods/lua/lua.h @@ -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(); diff --git a/mods/lua/make.bat b/mods/lua/make.bat index 37da498..a8d8e82 100755 --- a/mods/lua/make.bat +++ b/mods/lua/make.bat @@ -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 + diff --git a/mods/lua/wrappers.c b/mods/lua/wrappers.c index d823b0d..0be3f44 100755 --- a/mods/lua/wrappers.c +++ b/mods/lua/wrappers.c @@ -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); +}