diff --git a/admin-scripts/join.py b/admin-scripts/join.py deleted file mode 100755 index ab80177..0000000 --- a/admin-scripts/join.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -import socket - -sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -sockpath = "/root/sexiibot/sexiibot.sock" -try: - sock.connect(sockpath) -except socket.error: - sys.exit(1) - -try: - - # Send data - message = 'join #bordel' - sock.sendall(bytes(message, 'UTF-8')) - -finally: - sock.close() diff --git a/admin-scripts/leave.py b/admin-scripts/leave.py deleted file mode 100755 index 9bb24f4..0000000 --- a/admin-scripts/leave.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 - -import socket - -sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -sockpath = "/root/sexiibot/sexiibot.sock" -try: - sock.connect(sockpath) -except socket.error: - sys.exit(1) - -try: - - # Send data - message = 'leave #bordel' - sock.sendall(bytes(message, 'UTF-8')) - -finally: - sock.close() diff --git a/admin-scripts/sexiictl b/admin-scripts/sexiictl new file mode 100755 index 0000000..20a7a4e --- /dev/null +++ b/admin-scripts/sexiictl @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import socket +import sys +import os + +sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sockpath = "/var/tmp/%s/sexiibot.sock" % os.environ["USER"] + +logo = """\ + .-. + (/ \) + (\ /) SEXIIBOT : The Bot Of Your Dreams + .-'-. Simple EXtensible II Bot +/(_Y_)\\ v.0.1.1 +\\\\) (// + / \ Author: raspbeguy + \ Y / raspbeguy@hashtagueule.fr + \|/ + /|\ https://git.hashtagueule.fr/raspbeguy/sexiibot + \|/ + /Y\\ +""" + +usage = """\ +usage: %s [-p ] + +To get a list of possible commands, use command "help" +""" + +args = sys.argv + +if len(args) < 2: + print(usage, file=sys.stderr) + sys.exit(1) +elif args[1] == "-v": + print(logo) + sys.exit(0) +elif args[1] == "-p": + try: + sockpath = args[2] + except IndexError: + print(usage, file=sys.stderr) + sys.exit(1) + message = " ".join(args[3:]) +else: + message = " ".join(args[1:]) + +try: + print(message) + sock.connect(sockpath) +except socket.error: + error = """\ +It seems that sexiibot isn't awaken. +To start your sexiibot instance, run the following command: + sexiictl start + +It is also possible than the instance of sexiibot you're trying to reach uses a different control socket. +You can try running the following command : + sexiictl -p """ + "".join(sys.argv[1:]) + """ + +If you need help to generate a config file, use the sexiiwizard script. +""" + print(error, file=sys.stderr) + sys.exit(1) +try: + sock.sendall(bytes(message, 'UTF-8')) +finally: + sock.close() diff --git a/sexiibot/core.py b/sexiibot/core.py index 2ee6643..d497ec5 100644 --- a/sexiibot/core.py +++ b/sexiibot/core.py @@ -116,9 +116,11 @@ class Sexiibot(object): def leaveChan(self, args): if len(args) == 1: self.__channels[args[0]].leave() - if len(args) == 2: + elif if len(args) == 2: self.__channels[args[0]].leave(args[1]) - del self.__channel[args[0]] + else: + return "warning: \"%s\" garbage" + del self.__channels[args[0]] def incomingChan(self, dirname): root = self.getIrcPath() @@ -151,12 +153,12 @@ class Sexiibot(object): data = connection.recv(16) command += data.decode('UTF-8') if not data: - self.parseCommand(command) + self.parseCommand(command, connexion) break finally: connection.close() - def parseCommand(self, command): + def parseCommand(self, command, connexion): cmd = command.split(" ") order = { "join" : self.newChan, @@ -166,7 +168,7 @@ class Sexiibot(object): "action" : self.actionChan, "nick" : self.setNick } - order[cmd[0]](cmd[1:]) + #connection.sendall(order[cmd[0]](cmd[1:], 'UTF-8')) def quit(selfi, args=[]): for chan in self.__channels: