Client class

This commit is contained in:
Cadey Ratio 2019-12-25 22:48:28 +00:00
parent 559df11d41
commit 6f9a472818
5 changed files with 59 additions and 25 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
moonc-5.3 `find -type f | grep 'moon$'` moonc-5.3 `find -type f | grep -v spec | grep 'moon$'`
ngircd -f ./spec/ngircd.conf ngircd -f `pwd`/spec/ngircd.conf
function trap_ctrlc () { function trap_ctrlc () {
killall ngircd killall ngircd

View File

@ -34,6 +34,10 @@ Name = #lobby
Topic = Welcome to the new ShadowNET! Topic = Welcome to the new ShadowNET!
Modes = tn Modes = tn
[Operator]
Name = Cadey
Password = hunter2
[Server] [Server]
Name = ketracel.akua Name = ketracel.akua
Passive = yes Passive = yes

View File

@ -1,5 +1,6 @@
irce = require "irce" irce = require "irce"
socket = require "socket" socket = require "socket"
test = require "ketracel.test"
describe "ngircd protocol support", -> describe "ngircd protocol support", ->
local file local file
@ -42,27 +43,9 @@ describe "ngircd protocol support", ->
print "[server] " .. msg print "[server] " .. msg
irc\process msg irc\process msg
irc\clear_callback "376" @irc\clear_callback "376"
it "can do a normal client connection", -> it "can use the Client class", ->
irc_client = socket.tcp! cli = test.Client "test_user"
ircce = irce.new! cli\wait_for "005"
ircce\set_send_func (message) => cli\quit!
print "[client] > " .. message
irc_client\send message
running = true
ircce\set_callback "005", =>
running = false
ircce\load_module require "irce.modules.base"
irc_client\connect "127.0.0.1", 6667
ircce\NICK "test"
ircce\USER "test", "hunter2"
while running
msg = irc_client\receive!
print "[client] < " .. msg
ircce\process msg
ircce\QUIT "bye"
irc_client\close!

3
src/ketracel/Tupfile Normal file
View File

@ -0,0 +1,3 @@
include_rules
.gitignore

44
src/ketracel/test.moon Normal file
View File

@ -0,0 +1,44 @@
irce = require "irce"
socket = require "socket"
get_client_modules = (irc) ->
irc\load_module require "irce.modules.base"
irc\load_module require "irce.modules.message"
irc\load_module require "irce.modules.channel"
class Client
new: (nick) =>
@nick = nick
socket = socket.tcp!
irc = irce.new!
get_client_modules irc
irc\set_send_func (message) =>
print string.format "[client %s] > %s", nick, message
socket\send message
socket\connect "127.0.0.1", 6667
irc\NICK nick
irc\USER nick, nick
@socket = socket
@irc = irc
wait_for: (event) =>
running = true
nick = @nick
@irc\set_callback event, =>
print string.format "[client %s] ! got event %s", nick, event
running = false
while running
msg = @socket\receive!
print string.format "[client %s] < %s", nick, msg
@irc\process msg
quit: =>
@irc\QUIT "bye"
@socket\close!
{
:Client
}