Exemplo n.º 1
0
    def add_projects(self, arguments, messageInfo):
        message = arguments.split(" ")
        try:
            name = message[0]
            language = message[1]
            link = message[2]
            message.pop(0)
            message.pop(0)
            message.pop(0)
            description = ' '.join(message)
        except IndexError:
            ircHelpers.privateMessage(
                messageInfo['user'],
                "Correct usage is: !!addproject [name] [language] [link] [description]"
            )
            return False

        proj_id = binascii.b2a_hex(os.urandom(3)).decode()
        proj_dict = {
            "name": name,
            "language": language,
            "link": link,
            "description": description.strip("\r"),
            "id": proj_id
        }
        if DB().db_add_data("projects", proj_dict):
            ircHelpers.pmInChannel(
                messageInfo['user'],
                "Added project %s. Thank's for taking part!" % name)
            ircHelpers.sayInChannel("Added new project: %s" % name)
        else:
            ircHelpers.privateMessage(messageInfo['user'],
                                      "Error trying to add project %s" % name)
Exemplo n.º 2
0
 def readChatLog(self, arguments, messageInfo):
     index = -10
     while index <= -1:
         try:
             ircHelpers.privateMessage(messageInfo['user'], '%s: %s' % (self.chatLog[index]['user'], self.chatLog[index]['message']))
             index += 1
         except:
             index += 1
Exemplo n.º 3
0
    def aid(self, arguments, messageInfo):
        args = arguments.split()
        requesting_user = messageInfo['user']

        # can't use without args so give them the help for the command
        if len(args) == 0:
            help_messages = self.__getCommandHelpFromAddon(self.title, 'aid', False)
            ircHelpers.privateMessage(requesting_user, *help_messages)
        else:
            ##TODO Perform test for user online and known to bot
            target_user = args.pop(0)
            self.__giveHelp(target_user, args)
Exemplo n.º 4
0
 def get_mail(self, arguments, messageInfo):
     recipient = messageInfo["user"]
     data = DB().db_get_data("mail", "recipient", recipient)
     if data == None:
         ircHelpers.pmInChannel(messageInfo["user"], "Error retrieving mail")
         return False
     elif len(data) == 0:
         ircHelpers.pmInChannel(messageInfo["user"], "You have no messages")
         return True
     else:
         for mail_tuple in data:
             ircHelpers.privateMessage(mail_tuple[1], "[ %s ] <%s>: %s" % (mail_tuple[3],mail_tuple[0],mail_tuple[2]))
         return True
Exemplo n.º 5
0
 def readChatLog(self, arguments, messageInfo):
     if arguments == '':
         index = -10
     else:
         index = int(int(arguments) / -1)
     while index <= -1:
         try:
             ircHelpers.privateMessage(
                 messageInfo['user'],
                 '%s: %s' % (self.chatLog[index]['user'],
                             self.chatLog[index]['message']))
             index += 1
         except:
             index += 1
Exemplo n.º 6
0
    def list_projects(self, arguments, messageInfo):
        user = messageInfo['user']
        if not DB().db_check_table("projects"):
            DB().db_add_table(
                "projects",
                "name text, language text, link text, description text, id text"
            )
        if (arguments):
            data = DB().db_get_data("projects", "language",
                                    arguments.replace('\r', ''))
        else:
            data = DB().db_get_all_data("projects")
        if data == None:
            ircHelpers.privateMessage(
                user, "Error while trying to retrieve Projects")
        if len(data) == 0:
            ircHelpers.privateMessage(user, "There are no listed projects")
        else:
            max_name = len("name")
            max_lang = len("language")
            max_desc = len("description")
            max_link = 0
            for proj_tuple in data:
                if len(proj_tuple[1]) > max_lang:
                    max_lang = len(proj_tuple[1])
                if len(proj_tuple[0]) > max_name:
                    max_name = len(proj_tuple[0])
                if len(proj_tuple[3]) > max_desc:
                    max_desc = len(proj_tuple[3])
                if len(proj_tuple[2]) > max_link:
                    max_link = len(proj_tuple[2])
            title_row = "(%s)  %s [[ %s ]]  %s  (( %s ))" % (
                "  id  ", "language".ljust(max_lang), "name".ljust(max_name),
                "description".ljust(max_desc), "   link".ljust(max_link))

            ircHelpers.privateMessage(user, title_row)
            ircHelpers.privateMessage(user, '-' * len(title_row))

            for proj_tuple in data:
                ircHelpers.privateMessage(
                    user,
                    #(id) lang [[ name ]]  desc  << link >>
                    "(%s)  %s [[ %s ]]  %s  (( %s ))" % (
                        proj_tuple[4],  # id
                        proj_tuple[1].ljust(max_lang),  # lang
                        proj_tuple[0].ljust(max_name),  # name
                        proj_tuple[3].ljust(max_desc),  # desc
                        proj_tuple[2].ljust(max_link)))  # link
Exemplo n.º 7
0
 def get_mail(self, arguments, messageInfo):
     recipient = messageInfo["user"]
     data = DB().db_get_data("mail", "recipient", recipient)
     if data == None:
         ircHelpers.pmInChannel(messageInfo["user"],
                                "Error retrieving mail")
         return False
     elif len(data) == 0:
         ircHelpers.pmInChannel(messageInfo["user"], "You have no messages")
         return True
     else:
         for mail_tuple in data:
             ircHelpers.privateMessage(
                 mail_tuple[1], "[ %s ] <%s>: %s" %
                 (mail_tuple[3], mail_tuple[0], mail_tuple[2]))
         return True
Exemplo n.º 8
0
    def __giveHelp(self, user, split_arguments, times_run=0):
        if times_run > 5:
            print(
                "!! Too many recursive calls to Help.__giveHelp(). Giving up.")
            return

        num_args = len(split_arguments)

        # bare 'help' command on its own
        if num_args == 0:
            if self.debug: print("== No args, giving default")
            help_message = [
                "Welcome to progether! There may not always be a lot of activity here, just stick around. IRC use requires some patience. All commands for the bots can also be done by private messages: /msg {0} {1}[command] [**args]"
                .format(ircBot.nickname, Helper.PREFIX),
                "{0}The format is: {1}help ['commands'/'addons'/commandName/addonName]"
                .format(Helper.INDENT, Helper.PREFIX),
            ]
            ircHelpers.privateMessage(user, *help_message)

        # has arguments we need to parse
        else:
            first_arg = split_arguments[0].lower()

            # display all help at once:
            if first_arg in ('all', 'a'):
                if self.debug: print("== Found CASE_ALL")
                help_messages = self.__getAllHelp()
                ircHelpers.privateMessage(user, *help_messages)

            # list all addon packages and descriptions
            elif first_arg in ('addons', 'add'):
                if self.debug: print("== Found CASE_ADDONS")
                help_messages = self.__getAllAddonDescriptions()
                ircHelpers.privateMessage(user, *help_messages)

            # list all commands available in short form (for recap):
            elif first_arg in ('commands', 'cmds'):
                if self.debug: print("== Found CASE_CMDS")
                help_messages = self.__getAllCompactAddonHelp()
                ircHelpers.privateMessage(user, *help_messages)

            # otherwise parse argument as a command
            else:
                if self.debug:
                    print("== No mods left. Parse cmd: " + split_arguments[0])
                help_messages = self.__getHelpForSingleCmd(split_arguments[0])
                ircHelpers.privateMessage(user, *help_messages)
Exemplo n.º 9
0
    def list_projects(self, arguments, messageInfo):
        user = messageInfo['user']
        if not DB().db_check_table("projects"):
            DB().db_add_table("projects", "name text, language text, link text, description text, id text")
        if (arguments):
            data = DB().db_get_data("projects", "language", arguments.replace('\r',''))
        else:
            data = DB().db_get_all_data("projects")
        if data == None:
            ircHelpers.privateMessage(user, "Error while trying to retrieve Projects")
        if len(data) == 0:
            ircHelpers.privateMessage(user, "There are no listed projects")
        else:
            max_name = len("name")
            max_lang = len("language")
            max_desc = len("description")
            max_link = 0
            for proj_tuple in data:
                if len(proj_tuple[1]) > max_lang:
                    max_lang = len(proj_tuple[1])
                if len(proj_tuple[0]) > max_name:
                    max_name = len(proj_tuple[0])
                if len(proj_tuple[3]) > max_desc:
                    max_desc = len(proj_tuple[3])
                if len(proj_tuple[2]) > max_link:
                    max_link = len(proj_tuple[2])
            title_row = "(%s)  %s [[ %s ]]  %s  (( %s ))" %(
                                     "  id  ",
                                     "language".ljust(max_lang),
                                     "name".ljust(max_name),
                                     "description".ljust(max_desc),
                                     "   link".ljust(max_link))

            ircHelpers.privateMessage(user, title_row)
            ircHelpers.privateMessage(user, '-'*len(title_row))

            for proj_tuple in data:
                ircHelpers.privateMessage(user, 
                                       #(id) lang [[ name ]]  desc  << link >>
                                       "(%s)  %s [[ %s ]]  %s  (( %s ))"
                                       % (proj_tuple[4],                  # id
                                          proj_tuple[1].ljust(max_lang),  # lang
                                          proj_tuple[0].ljust(max_name),  # name
                                          proj_tuple[3].ljust(max_desc),  # desc
                                          proj_tuple[2].ljust(max_link))) # link
Exemplo n.º 10
0
    def __giveHelp(self, user, split_arguments, times_run=0):
        if times_run > 5:
            print("!! Too many recursive calls to Help.__giveHelp(). Giving up.")
            return

        num_args = len(split_arguments)

        # bare 'help' command on its own
        if num_args == 0:
            if self.debug: print("== No args, giving default")
            help_message = ["Welcome to progether! There may not always be a lot of activity here, just stick around. IRC use requires some patience. All commands for the bots can also be done by private messages: /msg {0} {1}[command] [**args]. For information about IRC read https://irchelp.org/irchelp/new2irc.html".format(ircBot.nickname, Helper.PREFIX),
                    "{0}The format is: {1}help ['commands'/'addons'/commandName/addonName] For more information on useage checkout https://github.com/Progether/IRC-Bot/blob/master/README.md".format(Helper.INDENT, Helper.PREFIX),]
            ircHelpers.privateMessage(user, *help_message)

        # has arguments we need to parse
        else:
            first_arg = split_arguments[0].lower()

            # display all help at once:
            if first_arg in ('all', 'a'):
                if self.debug: print("== Found CASE_ALL")
                help_messages = self.__getAllHelp()
                ircHelpers.privateMessage(user, *help_messages)

            # list all addon packages and descriptions
            elif first_arg in ('addons', 'add'):
                if self.debug: print("== Found CASE_ADDONS")
                help_messages = self.__getAllAddonDescriptions()
                ircHelpers.privateMessage(user, *help_messages)

            # list all commands available in short form (for recap):
            elif first_arg in ('commands', 'cmds'):
                if self.debug: print("== Found CASE_CMDS")
                help_messages = self.__getAllCompactAddonHelp()
                ircHelpers.privateMessage(user, *help_messages)

            # otherwise parse argument as a command
            else:
                if self.debug: print("== No mods left. Parse cmd: " +split_arguments[0])
                help_messages = self.__getHelpForSingleCmd(split_arguments[0])
                ircHelpers.privateMessage(user, *help_messages)
Exemplo n.º 11
0
    def add_projects(self, arguments, messageInfo):
        message = arguments.split(" ")
        try:
            name = message[0]
            language = message[1]
            link = message[2]
            message.pop(0)
            message.pop(0)
            message.pop(0)
            description = ' '.join(message)
        except IndexError:
            ircHelpers.privateMessage(messageInfo['user'], "Correct usage is: !!addproject [name] [language] [link] [description]")
            return False

        proj_id = binascii.b2a_hex(os.urandom(3)).decode()
        proj_dict = { "name" : name, "language" : language, "link" : link, "description" : description.strip("\r"), "id" : proj_id }
        if DB().db_add_data("projects", proj_dict):
            ircHelpers.pmInChannel(messageInfo['user'], "Added project %s. Thank's for taking part!" % name)
            ircHelpers.sayInChannel("Added new project: %s" % name)
        else:
            ircHelpers.privateMessage(messageInfo['user'], "Error trying to add project %s" % name)
Exemplo n.º 12
0
 def delete_projects(self, arguments, messageInfo):
     if not arguments.strip('\r').strip():
         ircHelpers.privateMessage(messageInfo['user'], "Correct usage is: !!delproject [project_id]")
         return False
     if DB().db_delete_data("projects", "id", arguments.strip('\r')):
         ircHelpers.privateMessage(messageInfo['user'], "Deleted project (if available)")
         return True
     else:
         ircHelpers.privateMessage(messageInfo['user'], "Error trying to delete project")
         return False
Exemplo n.º 13
0
 def delete_projects(self, arguments, messageInfo):
     if not arguments.strip('\r').strip():
         ircHelpers.privateMessage(
             messageInfo['user'],
             "Correct usage is: !!delproject [project_id]")
         return False
     if DB().db_delete_data("projects", "id", arguments.strip('\r')):
         ircHelpers.privateMessage(messageInfo['user'],
                                   "Deleted project (if available)")
         return True
     else:
         ircHelpers.privateMessage(messageInfo['user'],
                                   "Error trying to delete project")
         return False
Exemplo n.º 14
0
 def notify(self, user):
   if user in self.mailDict:
     if len(self.mailDict[user]) > 0:
       ircHelpers.privateMessage(user, 'you have mail, !!mymail to view')
Exemplo n.º 15
0
 def myMail(self, arguments, messageInfo):
   if messageInfo['user'] in mailDict:
     for mail in self.mailDict[messageInfo['user']]:
       ircHelpers.privateMessage(messageInfo['user'], mail)
       self.mailDict[messageInfo['user']] = list()