Created
August 23, 2013 03:51
-
-
Save Longlius/6315377 to your computer and use it in GitHub Desktop.
excerpt from derpybot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; derpybot.lisp - main program file | |
(in-package #:derpybot) | |
;;; TOP-LEVEL DEFINITIONS | |
;;; *irc-host* - hostname of IRC server to connect to | |
(defparameter *irc-host* (string "irc.rizon.net")) | |
;;; *irc-port* - port number of IRC server to connect to | |
(defparameter *irc-port* 6660) | |
;;; *irc-nick* - nick for the bot to connect with | |
(defparameter *irc-nick* (string "DerpyBot")) | |
;;; *irc-pass* - password for nickserv identification | |
;;; (if nil, do not identify with nickserv) | |
(defparameter *irc-pass* nil) | |
;;; *irc-user* - username for bot | |
(defparameter *irc-user* (string "DerpyBot")) | |
;;; *irc-host* - hostname for bot | |
(defparameter *irc-host* (string "Alice")) | |
;;; *irc-socket* - global variable for usocket:stream-usocket | |
;;; currently connected to the IRC server | |
(defparameter *irc-socket* nil) | |
;;; *irc-stream* - global variable for stream associated | |
;;; with *irc-socket* | |
(defparameter *irc-stream* nil) | |
;;; FUNCTIONS | |
;;; irc-print - prints over a stream to the server | |
;;; appending CRLF per RFC | |
(defun irc-print (object &optional output-stream) | |
(let ((s (if output-stream output-stream *irc-stream*))) | |
(princ object s) | |
(write-char #\return s) | |
(write-char #\newline s) | |
(force-output s))) | |
;;; irc-read - reads a line from the server using | |
;;; CR as the eof-value | |
(defun irc-read (&optional input-stream) | |
(read-line (if input-stream input-stream *irc-stream*) | |
't '#\return 'nil)) | |
;;; main - program entry point | |
(defun main () | |
(progn (setq *irc-socket* (usocket:socket-connect *irc-host* *irc-port*)) | |
(setq *irc-stream* (usocket:socket-stream *irc-socket*)) | |
(loop (if (listen *irc-stream*) | |
(progn (princ (irc-read)) | |
(fresh-line)) | |
)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment