#include <stdio.h>
-#include <string.h>
#include <time.h>
+#include <dirent.h>
#include "../nick/nick.h"
#include "../localuser/localuserchannel.h"
int qabot_dochananswer(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
int id;
char* ch;
qab_question* q;
int qabot_dochanblock(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
qab_block* b;
if (cargc < 1) {
if (!strchr(mask, '@') || !strchr(mask, '!')) {
sendnoticetouser(bot->np, sender, "%s is not a valid hostmask.", mask);
- return;
+ return CMD_ERROR;
}
b = (qab_block*)malloc(sizeof(qab_block));
if (!(qnick = getnickbynumeric(q->numeric)))
continue;
- sprintf(hostbuf, "%s!%s@%s", qnick->nick, qnick->ident, qnick->host->name->content);
+ sprintf(hostbuf,"%s!%s@%s", qnick->nick, qnick->ident, qnick->host->name->content);
if (match(b->blockstr, hostbuf))
continue;
}
int qabot_dochanclear(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
channel* cp = qabot_getcurrentchannel();
qab_spam* s;
qab_spam* ns;
- qab_answer* a;
- qab_answer* na;
-
- if (bot->recording_section) {
- sendmessagetochannel(bot->np, cp, "Deactivate recorder before using clear.");
- return CMD_ERROR;
- }
for (s = bot->nextspam; s; s = ns) {
ns = s->next;
bot->micnumeric = 0;
sendmessagetochannel(bot->np, cp, "Mic deactivated.");
}
+ if (bot->recnumeric) {
+ bot->recnumeric = 0;
+ sendmessagetochannel(bot->np, cp, "Recorder deactivated.");
+ }
+ if (bot->recfile) {
+ fclose(bot->recfile);
+ bot->recfile = NULL;
+ }
+ if (bot->playfile) {
+ fclose(bot->playfile);
+ bot->playfile = NULL;
+ }
return CMD_OK;
}
int qabot_dochanclosechan(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
modechanges changes;
localsetmodeinit(&changes, bot->public_chan->channel, bot->np);
int qabot_dochanconfig(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
char* opt;
char* value;
int qabot_dochanhelp(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
char* ch;
if (cargc < 1)
ch = cargv[0];
if (*ch) {
- if (!ircd_strcmp(ch, "mic")) {
+ if (!ircd_strcmp(ch, "record")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !record [filename]");
+ sendnoticetouser(bot->np, sender, "Turn the recorder on or off. When turned on, anything said is recorded.");
+ sendnoticetouser(bot->np, sender, "File name is required when starting the recorder.");
+ }
+ else if (!ircd_strcmp(ch, "play")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !play <filename>");
+ sendnoticetouser(bot->np, sender, "Begin playback from the file specified.");
+ }
+ else if (!ircd_strcmp(ch, "continue")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !continue");
+ sendnoticetouser(bot->np, sender, "Continue playback from a file.");
+ }
+ else if (!ircd_strcmp(ch, "stop")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !stop");
+ sendnoticetouser(bot->np, sender, "Stop playback of a file before it reaches the end.");
+ }
+ else if (!ircd_strcmp(ch, "list")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !list");
+ sendnoticetouser(bot->np, sender, "Lists recording files.");
+ }
+ else if (!ircd_strcmp(ch, "delete")) {
+ sendnoticetouser(bot->np, sender, "Syntax: !delete <filename>");
+ sendnoticetouser(bot->np, sender, "Deletes a recording file.");
+ }
+ else if (!ircd_strcmp(ch, "mic")) {
sendnoticetouser(bot->np, sender, "Syntax: !mic");
sendnoticetouser(bot->np, sender, "Turn the microphone on or off. When turned on, anything said by the microphone holder is relayed to %s.", bot->public_chan->name->content);
}
sendnoticetouser(bot->np, sender, "!spam - Mark a question or questions as spam.");
sendnoticetouser(bot->np, sender, "!status - Display some status statistics.");
sendnoticetouser(bot->np, sender, "!unblock - Remove a block.");
+ sendnoticetouser(bot->np, sender, "!record - Turn the recorder on or off.");
+ sendnoticetouser(bot->np, sender, "!play - Start playback of a recording.");
+ sendnoticetouser(bot->np, sender, "!continue - Continue playback of a recording.");
+ sendnoticetouser(bot->np, sender, "!stop - Stop playback of a recording.");
+ sendnoticetouser(bot->np, sender, "!list - Lists recordings.");
+ sendnoticetouser(bot->np, sender, "!delete - Deletes a previous recording.");
sendnoticetouser(bot->np, sender, "End of list.");
}
int qabot_dochanlistblocks(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
qab_block* b;
if (!(b = bot->blocks)) {
sendnoticetouser(bot->np, sender, "There are no blocks currently added.");
- return;
+ return CMD_ERROR;
}
sendnoticetouser(bot->np, sender, "Type: Hostmask/Account/Textmask:");
qab_bot* bot = qabot_getcurrentbot();
channel* cp = qabot_getcurrentchannel();
- if (bot->recording_section)
- sendmessagetochannel(bot->np, cp, "Deactivate recorder before attempting to use mic.");
- else if (bot->micnumeric) {
+ if (bot->micnumeric) {
if (bot->micnumeric == sender->numeric) {
bot->micnumeric = 0;
sendmessagetochannel(bot->np, cp, "Mic deactivated.");
return CMD_OK;
}
-int qabot_dochanmoo(void* np, int cargc, char** cargv) {
+int qabot_dochanrecord(void *np, int cargc, char** cargv) {
+ char buf[200];
+ unsigned int i, filenamelen;
+ nick* sender = (nick*)np;
+ qab_bot* bot = qabot_getcurrentbot();
+ channel* cp = qabot_getcurrentchannel();
+
+ if (bot->recnumeric) {
+ if (bot->recnumeric == sender->numeric) {
+ bot->recnumeric = 0;
+ fclose(bot->recfile);
+ bot->recfile = NULL;
+ sendmessagetochannel(bot->np, cp, "Recorder deactivated.");
+ } else {
+ sendmessagetochannel(bot->np, cp, "Someone else is recording at the moment.");
+ return CMD_ERROR;
+ }
+ }
+ else {
+ if (bot->playfile) {
+ sendmessagetochannel(bot->np, cp, "You cannot record whilst a playback is in progress.");
+ return CMD_ERROR;
+ }
+
+ if (cargc < 1) {
+ sendmessagetochannel(bot->np, cp, "You did not specify a file name.");
+ return CMD_ERROR;
+ }
+
+ filenamelen = strlen(cargv[0]);
+
+ if (filenamelen > 50) {
+ sendmessagetochannel(bot->np, cp, "File name too long.");
+ return CMD_ERROR;
+ }
+
+ for (i = 0; i < filenamelen; i++) {
+ if (cargv[0][i] < '0' || (cargv[0][i] > '9' && cargv[0][i] < 'A') || (cargv[0][i] > 'Z' && cargv[0][i] < 'a') || cargv[0][i] > 'z') {
+ sendmessagetochannel(bot->np, cp, "Invalid characters in file name.");
+ return CMD_ERROR;
+ }
+ }
+
+ snprintf(buf, 150, "./qabotrecords/%s_%s", bot->nick, cargv[0]);
+ bot->recfile = fopen(buf, "w");
+
+ if (!(bot->recfile)) {
+ sendmessagetochannel(bot->np, cp, "Could not open record file.");
+ return CMD_ERROR;
+ }
+
+ bot->recnumeric = sender->numeric;
+
+ sendmessagetochannel(bot->np, cp, "Recorder activated. Anything said by %s will be recorded.",
+ sender->nick);
+ }
+ return CMD_OK;
+}
+
+int qabot_dochanplay(void *np, int cargc, char** cargv) {
+ char buf[200];
+ unsigned int i, filenamelen;
+ qab_bot* bot = qabot_getcurrentbot();
+ channel* cp = qabot_getcurrentchannel();
+
+ if (bot->playfile) {
+ sendmessagetochannel(bot->np, cp, "A playback is already in progress, use !stop to abort current playback.");
+ return CMD_ERROR;
+ }
+
+ if (bot->recfile) {
+ sendmessagetochannel(bot->np, cp, "You cannot playback whilst recording is in progress.");
+ return CMD_ERROR;
+ }
+
+ if (cargc < 1) {
+ sendmessagetochannel(bot->np, cp, "You did not specify a file name.");
+ return CMD_ERROR;
+ }
+
+ filenamelen = strlen(cargv[0]);
+
+ if (filenamelen > 50) {
+ sendmessagetochannel(bot->np, cp, "File name too long.");
+ return CMD_ERROR;
+ }
+
+ for (i = 0; i < filenamelen; i++) {
+ if (cargv[0][i] < '0' || (cargv[0][i] > '9' && cargv[0][i] < 'A') || (cargv[0][i] > 'Z' && cargv[0][i] < 'a') || cargv[0][i] > 'z') {
+ sendmessagetochannel(bot->np, cp, "Invalid characters in file name.");
+ return CMD_ERROR;
+ }
+ }
+
+ snprintf(buf, 150, "./qabotrecords/%s_%s", bot->nick, cargv[0]);
+ bot->playfile = fopen(buf, "r");
+
+ if (!(bot->playfile)) {
+ sendmessagetochannel(bot->np, cp, "Could not open playback file.");
+ return CMD_ERROR;
+ }
+
+ sendmessagetochannel(bot->np, cp, "Starting playback...");
+ qabot_playback(bot);
+ return CMD_OK;
+}
+
+int qabot_dochancontinue(void *np, int cargc, char** cargv) {
+ qab_bot* bot = qabot_getcurrentbot();
+ channel* cp = qabot_getcurrentchannel();
+
+ if (!(bot->playfile)) {
+ sendmessagetochannel(bot->np, cp, "No playback in progress.");
+ return CMD_ERROR;
+ }
+
+ sendmessagetochannel(bot->np, cp, "Continuing playback...");
+ qabot_playback(bot);
+ return CMD_OK;
+}
+
+int qabot_dochanstop(void *np, int cargc, char** cargv) {
+ qab_bot* bot = qabot_getcurrentbot();
+ channel* cp = qabot_getcurrentchannel();
+
+ if (!(bot->playfile)) {
+ sendmessagetochannel(bot->np, cp, "No playback in progress.");
+ return CMD_ERROR;
+ }
+
+ fclose(bot->playfile);
+ bot->playfile = NULL;
+ sendmessagetochannel(bot->np, cp, "Stopped playback.");
+ return CMD_OK;
+}
+
+int qabot_dochanlist(void *np, int cargc, char** cargv) {
+ DIR *recordlist;
+ struct dirent *direntry;
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
+
+ recordlist = opendir("./qabotrecords");
+
+ if (!recordlist) {
+ sendnoticetouser(bot->np, sender, "Unable to retreive directory list.");
+ return CMD_ERROR;
+ }
+
+ sendnoticetouser(bot->np, sender, "Recording list:");
+
+ for (direntry = readdir(recordlist); direntry; direntry = readdir(recordlist)) {
+ if (direntry->d_name[0] == '.')
+ continue;
+
+ sendnoticetouser(bot->np, sender, " %s", direntry->d_name);
+ }
+
+ sendnoticetouser(bot->np, sender, "End of list.");
+ closedir(recordlist);
+
+ return CMD_OK;
+}
+
+int qabot_dochandelete(void *np, int cargc, char** cargv) {
+ char buf[200];
+ unsigned int i, filenamelen;
+ qab_bot* bot = qabot_getcurrentbot();
channel* cp = qabot_getcurrentchannel();
+
+ if (bot->playfile) {
+ sendmessagetochannel(bot->np, cp, "You cannot delete recordings whilst playback is in progress.");
+ return CMD_ERROR;
+ }
+
+ if (bot->recfile) {
+ sendmessagetochannel(bot->np, cp, "You cannot delete recordings whilst recording is in progress.");
+ return CMD_ERROR;
+ }
+
+ if (cargc < 1) {
+ sendmessagetochannel(bot->np, cp, "You did not specify a file name.");
+ return CMD_ERROR;
+ }
+
+ filenamelen = strlen(cargv[0]);
+
+ if (filenamelen > 50) {
+ sendmessagetochannel(bot->np, cp, "File name too long.");
+ return CMD_ERROR;
+ }
+
+ for (i = 0; i < filenamelen; i++) {
+ if (cargv[0][i] < '0' || (cargv[0][i] > '9' && cargv[0][i] < 'A') || (cargv[0][i] > 'Z' && cargv[0][i] < 'a') || cargv[0][i] > 'z') {
+ sendmessagetochannel(bot->np, cp, "Invalid characters in file name.");
+ return CMD_ERROR;
+ }
+ }
+
+ snprintf(buf, 150, "./qabotrecords/%s_%s", bot->nick, cargv[0]);
+
+ if (!remove(buf)) {
+ sendmessagetochannel(bot->np, cp, "Recording deleted.");
+ } else {
+ sendmessagetochannel(bot->np, cp, "Unable to delete recording.");
+ }
+
+ return CMD_OK;
+}
+
+int qabot_dochanmoo(void* np, int cargc, char** cargv) {
+ qab_bot* bot = qabot_getcurrentbot();
char moostr[50];
int i, moocount = 5 + (rand() % 40);
+ channel* cp = qabot_getcurrentchannel();
moostr[0] = 'm';
for (i = 1; i < moocount; i++)
int qabot_dochanofftopic(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
int id;
int i;
qab_question* q;
int qabot_dochanopenchan(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
modechanges changes;
localsetmodeinit(&changes, bot->public_chan->channel, bot->np);
}
int qabot_dochanping(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
channel* cp = qabot_getcurrentchannel();
int qabot_dochanreset(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
int r = 0;
if (cargc < 1) {
r = 3;
else {
sendnoticetouser(bot->np, sender, "Unknown parameter: %s.", cargv[0]);
- return;
+ return CMD_ERROR;
}
if (r & 1) {
int qabot_dochanspam(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
int id;
int i;
qab_question* q;
int qabot_dochanstatus(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
sendnoticetouser(bot->np, sender, "Lines spammed: %d", bot->spammed);
sendnoticetouser(bot->np, sender, "Questions asked: %d", bot->lastquestionID);
int qabot_dochanunblock(void* np, int cargc, char** cargv) {
nick* sender = (nick*)np;
qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
char* ch;
qab_block* b;
char type = -1;
return CMD_ERROR;
}
-
-int qabot_dochanlisttexts(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
-
- if (!texts) {
- sendnoticetouser(bot->np, sender, "There are no texts added.");
- return CMD_ERROR;
- }
-
- sendnoticetouser(bot->np, sender, "Name: Sections:");
- for (; texts; texts = texts->next) {
- sendnoticetouser(bot->np, sender, "%-15s %d", texts->name, texts->section_count);
- }
-
- sendnoticetouser(bot->np, sender, "End of list.");
-
- return CMD_OK;
-}
-
-int qabot_dochanshowsection(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
- qab_textsection* section;
- int count = 0;
-
- if (cargc < 2) {
- sendnoticetouser(bot->np, sender, "Syntax: !showsection <text name> <section number>");
- return CMD_ERROR;
- }
-
- if (!texts) {
- sendnoticetouser(bot->np, sender, "There are no texts added.");
- return CMD_ERROR;
- }
-
- id = (int)strtol(cargv[1]);
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- for (section = texts->sections; section && (count <= section->section_count); section = section->next) {
- if (++count == id) {
- qab_spam* lines;
- int lineno = 0;
-
- sendnoticetouser(bot->np, sender, "Section %d (of text %s) contents:", count, texts->name);
- for (lines = section->lines; lines; lines = lines->next)
- sendnoticetouser(bot->np, sender, "%-2d> %s", ++lineno, lines->message);
- sendnoticetouser(bot->np, sender, "End of section.");
-
- return CMD_OK;
- }
- }
- sendnoticetouser(bot->np, sender, "No such section.");
- return CMD_ERROR;
- }
- }
-
- sendnoticetouser(bot->np, sender, "No such text.");
-
- return CMD_ERROR;
-}
-
-int qabot_dochanaddtext(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
-
- if (cargc < 1) {
- sendnoticetouser(bot->np, sender, "Syntax: !addtext <text name>");
- return CMD_ERROR;
- }
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- sendnoticetouser(bot->np, sender, "A text with this name already exists.");
- return CMD_ERROR;
- }
- }
-
- texts = (qab_text*)malloc(sizeof(qab_text));
- strncpy(texts->name, cargc[0], NICKLEN);
- texts->name[NICKLEN] = '\0';
- texts->sections = 0;
- texts->sections_tail = 0;
- texts->section_count = 0;
- texts->next = bot->texts;
- texts->prev = 0;
- if (bot->texts)
- bot->texts->prev = texts;
- bot->texts = texts;
-
- sendnoticetouser(bot->np, sender, "Added text '%s'.", texts->name);
-
- return CMD_OK;
-}
-
-int qabot_dochandeltext(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
-
- if (cargc < 1) {
- sendnoticetouser(bot->np, sender, "Syntax: !deltext <text name>");
- return CMD_ERROR;
- }
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- sendnoticetouser(bot->np, sender, "Text '%s' deleted.", texts->name);
- qabot_freetext(bot, texts);
- return CMD_OK;
- }
- }
-
- sendnoticetouser(bot->np, sender, "No such text.");
-
- return CMD_ERROR;
-}
-
-int qabot_dochanaddsection(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
- qab_textsection* section;
-
- if (cargc < 1) {
- sendnoticetouser(bot->np, sender, "Syntax: !addsection <text name> [<section number>]");
- return CMD_ERROR;
- }
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- int num;
- if (cargc == 1 || !texts->sections_tail) {
- section = (qab_textsection*)malloc(sizeof(qab_textsection));
- section->lines = 0;
- section->lines_tail = 0;
- section->line_count = 0;
- section->prev = 0;
- section->next = 0;
- texts->sections = section;
- texts->sections_tail = section;
- texts->section_count++;
- num = 1;
- }
- else {
- }
-
- sendnoticetouser(bot->np, sender, "Section %d added.", num);
- return CMD_OK;
- }
- }
-
- sendnoticetouser(bot->np, sender, "No such text.");
-
- return CMD_ERROR;
-}
-
-int qabot_dochandelsection(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- qab_text* texts = bot->texts;
- qab_textsection* section;
-
- if (cargc < 2) {
- sendnoticetouser(bot->np, sender, "Syntax: !delsection <text name> <section number>");
- return CMD_ERROR;
- }
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- for (section = texts->sections; section && (count <= section->section_count); section = section->next) {
- if (++count == id) {
- qabot_freesection(texts, section);
- sendnoticetouser(bot->np, sender, "Section deleted.");
- return CMD_OK;
- }
- }
- sendnoticetouser(bot->np, sender, "No such section.");
- return CMD_ERROR;
- }
- }
-
- sendnoticetouser(bot->np, sender, "No such text.");
-
- return CMD_ERROR;
-}
-
-int qabot_dochanrecord(void* np, int cargc, char** cargv) {
- nick* sender = (nick*)np;
- qab_bot* bot = qabot_getcurrentbot();
- channel* cp = qabot_getcurrentchannel();
-
- if (bot->recording_section) {
- if (bot->micnumeric == sender->numeric) {
- bot->micnumeric = 0;
- bot->recording_section = 0;
- sendmessagetochannel(bot->np, cp, "Recorder deactivated.");
- }
- else {
- sendmessagetochannel(bot->np, cp, "The recorder is already in use.");
- }
- }
- else if (bot->micnumeric)
- sendmessagetochannel(bot->np, cp, "Deactivate mic before attempting to use recorder.");
- else if (cargc >= 2) {
- qab_text* texts = bot->texts;
- qab_textsection* section;
- int id = (int)strtol(cargv[1]);
-
- for (; texts; texts = texts->next) {
- if (!ircd_strcmp(texts->name, cargv[0])) {
- for (section = texts->sections; section && (count <= section->section_count); section = section->next) {
- if (++count == id) {
- bot->lastmic = time(NULL);
- bot->micnumeric = sender->numeric;
- bot->recording_section = count;
- sendmessagetochannel(bot->np, cp, "Recorder activated. Anything said by %s will be relayed in %s.",
- sender->nick, bot->public_chan->name->content);
- deleteschedule(0, qabot_spamstored, (void*)bot);
- return CMD_OK;
- }
- }
- sendnoticetouser(bot->np, sender, "No such section.");
- return CMD_ERROR;
- }
- }
-
- sendnoticetouser(bot->np, sender, "No such text.");
- return CMD_ERROR;
- }
- else
- sendmessagetochannel(bot->np, cp, "syntax: !record [<text name> <section number>]");
-
- return CMD_OK;
-}