Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Sockets.connect
- server = "chat.freenode.net"
- port = 6667
- c = connect(server, port)
- write(c, "USER julia|bot julialang|bot julialang|bot :This is a fun bot!\r\n")
- write(c, "NICK julia|bot\r\n")
- write(c, "PRIVMSG nickserv :iNOOPE\r\n")
- #write(c, "PRIVMSG nickserv :identify blabla\r\n")
- sleep(5)
- channels = ["#gentoo-weed"]
- for chan in channels
- write(c, "JOIN $chan\r\n")
- end
- oo = stdout
- PREF = "|"
- while true
- msg = readline(c)
- redirect_stdout(oo)
- println(msg)
- if findfirst("PING", msg) == 1:4
- r = split(msg)[2]
- pong = "PONG $r\r\n"
- write(c, pong)
- elseif occursin(" PRIVMSG", msg)
- who = match(r"^:(.*)!", msg)
- rcmd = Regex(string(" :\\",PREF,"(.*)"))
- cmd = match(rcmd, msg)
- channel = match(r"^.*?PRIVMSG (#.*) ", msg)
- if who != nothing && cmd != nothing && channel != nothing
- who = who[1]
- cmd = cmd[1]
- println(cmd)
- channel = channel[1]
- try
- (or, ow) = redirect_stdout()
- output = eval(Meta.parse(cmd))
- if output != nothing
- data = output
- else
- ra = readavailable(or)
- data = strip(String(ra))
- end
- ret = "PRIVMSG $channel :$data\r\n"
- write(c, ret)
- catch e
- ret = "PRIVMSG $channel :$e\r\n"
- write(c, ret)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement