werks
This commit is contained in:
parent
2d8f99036a
commit
68a65cffda
7
Makefile
7
Makefile
@ -22,7 +22,7 @@ HEADER := $(addprefix ${SOURCE.d}, ${HEADER})
|
||||
${OUT}: ${SOURCE} ${HEADER}
|
||||
${CC} ${CFLAGS} -o $@ ${SOURCE} ${LDLIBS}
|
||||
|
||||
run:
|
||||
run: ${OUT}
|
||||
${OUT} irc.rizon.net:6665 "#/g/test"
|
||||
|
||||
test: ${OUT}
|
||||
@ -30,8 +30,3 @@ test: ${OUT}
|
||||
|
||||
clean:
|
||||
-rm ${OUT}
|
||||
|
||||
docs:
|
||||
for i in documentation/*.md; do \
|
||||
kramdown-man "$$i" -o documentation/manual/$$(basename -s .md $$i) ; \
|
||||
done
|
||||
|
61
source/bot.h
61
source/bot.h
@ -3,6 +3,9 @@
|
||||
#include <libircclient.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
extern syntax_setter_t syntax_functions[];
|
||||
|
||||
irc_session_t * session;
|
||||
irc_callbacks_t callbacks;
|
||||
@ -11,6 +14,17 @@ void ircmsg(const char * const message) {
|
||||
irc_cmd_msg(session, channel, message);
|
||||
}
|
||||
|
||||
static
|
||||
language_t translate_language(const char * const language) {
|
||||
if (!strcmp(language, "C") || !strcmp(language, "C++")) {
|
||||
return C;
|
||||
} else if (!strcmp(language, "ADA")) {
|
||||
return ADA;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// XXX: msg ChanServ IDENTIFY?
|
||||
void event_connect(irc_session_t * session,
|
||||
const char * event,
|
||||
const char * origin,
|
||||
@ -21,7 +35,6 @@ void event_connect(irc_session_t * session,
|
||||
(void)params;
|
||||
(void)count;
|
||||
|
||||
// XXX: msg ChanServ IDENTIFY?
|
||||
log_notice("IRC connection secured.");
|
||||
irc_cmd_join(session, channel, 0);
|
||||
char * buffer;
|
||||
@ -39,15 +52,45 @@ void event_privmsg(irc_session_t * session,
|
||||
(void)event;
|
||||
(void)count;
|
||||
|
||||
char * buffer = (char *)origin;
|
||||
while (*(buffer++) != '!') { ; }
|
||||
asprintf(&buffer, "From %.*s:", (int)(buffer - origin)-1, origin);
|
||||
ircmsg(buffer);
|
||||
free(buffer);
|
||||
char * const message_guard = strdup(params[1]);
|
||||
char * message = message_guard;
|
||||
char * terminator;
|
||||
int is_code = 1;
|
||||
|
||||
char * message = strdup(params[1]);
|
||||
ircmsg(syntax_highlight(message));
|
||||
free(message);
|
||||
if (*message == '!') {
|
||||
terminator = message;
|
||||
while (*terminator != ' ') {
|
||||
if (*terminator == '\0') {
|
||||
is_code = 0;
|
||||
break;
|
||||
}
|
||||
++terminator;
|
||||
}
|
||||
*terminator = '\0';
|
||||
for (char * s = message + 1; *s != '\0'; s++) {
|
||||
*s = toupper(*s);
|
||||
}
|
||||
int l = translate_language(message + 1);
|
||||
message = terminator + 1;
|
||||
if (l != -1) {
|
||||
language = l;
|
||||
syntax_functions[language]();
|
||||
}
|
||||
}
|
||||
|
||||
if (is_code) {
|
||||
char * buffer = (char *)origin;
|
||||
while (*(buffer++) != '!') { ; }
|
||||
asprintf(&buffer, "From %.*s:", (int)(buffer - origin)-1, origin);
|
||||
ircmsg(buffer);
|
||||
free(buffer);
|
||||
|
||||
ircmsg(syntax_highlight(message));
|
||||
|
||||
ircmsg("--");
|
||||
}
|
||||
|
||||
free(message_guard);
|
||||
}
|
||||
|
||||
int connect_bot(const char * const server, const short port) {
|
||||
|
@ -7,6 +7,15 @@ char * channel;
|
||||
char * server;
|
||||
char * port;
|
||||
|
||||
typedef enum {
|
||||
C,
|
||||
ADA,
|
||||
} language_t;
|
||||
|
||||
language_t language = ADA;
|
||||
|
||||
typedef void (*syntax_setter_t)(void);
|
||||
|
||||
#include <stdio.h>
|
||||
FILE * log_file;
|
||||
|
||||
@ -14,6 +23,12 @@ FILE * log_file;
|
||||
#include "syntax.h"
|
||||
#include "bot.h"
|
||||
|
||||
syntax_setter_t syntax_functions[] = {
|
||||
[C] = &syntax_c,
|
||||
[ADA] = &syntax_ada,
|
||||
};
|
||||
|
||||
|
||||
const char help_message[] =
|
||||
PROGRAM_NAME " <server>:<port> <channel>\n"
|
||||
;
|
||||
@ -39,7 +54,7 @@ signed main(int argc, char * * argv) {
|
||||
|
||||
log_file = stdout;
|
||||
|
||||
syntax_c();
|
||||
syntax_functions[language]();
|
||||
|
||||
connect_bot(server, port_i);
|
||||
connection_loop();
|
||||
|
Loading…
Reference in New Issue
Block a user