+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;
+}
+