Commit 8ff4e068ec923155a32a450168b2c7c5bef2207a
- Diff rendering mode:
- inline
- side by side
ChangeLog
(13 / 0)
|   | |||
| 1 | 2009-07-04 Krister Svanlund <krister.svanlund@gmail.com> | ||
| 2 | |||
| 3 | * kofoo_set.py: Removed 'set quit' from help description since the command has | ||
| 4 | been removed. | ||
| 5 | |||
| 6 | * kofoo_help.py (do_help): Added 'level=' argument for help command to show help | ||
| 7 | for levels below the users. | ||
| 8 | (do_help_for): Changed output format to be prettier. | ||
| 9 | (do_help_for): Added the 'help commands' command for only listing availible commands. | ||
| 10 | (do_general_help): Changed output to fit indention to longest command+arguments | ||
| 11 | string. | ||
| 12 | |||
| 1 | 13 | 2009-07-03 Krister Svanlund <krister.svanlund@gmail.com> | |
| 2 | 14 | ||
| 3 | 15 | * kofoo_mediawiki.py (mw_get_url): Added function for getting the URL to a | |
| 4 | 16 | specific wiki-article. | |
| 5 | 17 | (do_wiki): Added search functionality for getting links to articles. | |
| 18 | Completed help information for the module. | ||
| 6 | 19 | ||
| 7 | 20 | 2009-07-02 Krister Svanlund <krister.svanlund@gmail.com> | |
| 8 | 21 |
Todo
(10 / 7)
|   | |||
| 44 | 44 | - [X] Check if updated | |
| 45 | 45 | - [X] Store last update | |
| 46 | 46 | - [X] Add functions for adding or removing streams at runtime. | |
| 47 | * Wiki [0/4] | ||
| 48 | - [ ] Check for changes (This can be done with RSS module) | ||
| 49 | - [ ] Post to wikipage. | ||
| 50 | - [ ] Create page if not existing. | ||
| 51 | - [ ] Add to correct subsection. | ||
| 52 | - [ ] Search for page and generate a link | ||
| 53 | - [ ] Add things to list | ||
| 47 | * Wiki [4/4] | ||
| 48 | - [X] Check for changes (This can be done with RSS module) | ||
| 49 | - [X] Post to wikipage. | ||
| 50 | - [X] Create page if not existing. | ||
| 51 | - [X] Add to correct subsection. | ||
| 52 | - [X] Add to list. | ||
| 53 | - [X] Add to table. | ||
| 54 | - [X] Create a table. | ||
| 55 | - [X] Search for page | ||
| 56 | - [X] Generate a links to pages | ||
| 54 | 57 | * URLGrabber [0/4] | |
| 55 | 58 | - [ ] Identify links in channel messages. | |
| 56 | 59 | - [ ] Filter links according to blacklist. |
kofoo_help.py
(63 / 16)
|   | |||
| 4 | 4 | ### Krister Svanlund <krister.svanlund gmail.com> ### | |
| 5 | 5 | ||
| 6 | 6 | import irclib | |
| 7 | import re | ||
| 7 | 8 | ||
| 8 | 9 | do_help_command = {'description': "Display this help or help for specific commands", | |
| 9 | 10 | 'arguments': [("", "Display general help and list commands availible to your level."), | |
| 10 | 11 | ("<command>", "Display help for a specific command."), | |
| 12 | ("commands", "Display a list of commands without description."), | ||
| 11 | 13 | ("alias", "List all aliases currently inplace."), | |
| 12 | 14 | ("modules", "List all modules that are loaded and that can be loaded.")], | |
| 13 | 15 | 'public': False, | |
| … | … | ||
| 18 | 18 | def do_help(self, server, sender, target, args): | |
| 19 | 19 | print "Show help to %s." % irclib.nm_to_n(sender) | |
| 20 | 20 | sender_level = self.get_level(sender) | |
| 21 | if len(args) > 0: | ||
| 21 | if args: | ||
| 22 | 22 | for command in args: | |
| 23 | m = re.match(r'level=([0-9]+)', command) | ||
| 24 | if m: | ||
| 25 | args.remove(m.group(0)) | ||
| 26 | try: sender_level = min(int(m.group(1)), sender_level) | ||
| 27 | except: sender_level = 0 | ||
| 28 | print " + Showing help for level %d." % sender_level | ||
| 29 | if args: | ||
| 30 | for command in args: | ||
| 23 | 31 | do_help_for(self, server, sender, target, command, sender_level) | |
| 24 | 32 | else: | |
| 25 | 33 | do_general_help(self, server, sender, target, sender_level) | |
| … | … | ||
| 44 | 44 | if sender_level < command_level: | |
| 45 | 45 | self.respond(server, sender, target, "You are not allowed to use this command.") | |
| 46 | 46 | return | |
| 47 | if command_description == "": | ||
| 48 | self.respond(server, sender, target, "There is no help for this command.") | ||
| 49 | return | ||
| 50 | 47 | if not type(command_arguments) is list: | |
| 51 | 48 | command_arguments = [command_arguments] | |
| 52 | 49 | if len(command_arguments) > 0: | |
| 50 | width = [] | ||
| 53 | 51 | for argument in command_arguments: | |
| 52 | if type(argument) is not tuple: | ||
| 53 | width.append(len(argument)) | ||
| 54 | else: | ||
| 55 | width.append(len(argument[0])) | ||
| 56 | if width: width = max(width) | ||
| 57 | else: width = 0 | ||
| 58 | for argument in command_arguments: | ||
| 54 | 59 | if type(argument) is tuple: | |
| 55 | help_string += " \x02Syntax:\x02 %s %s - %s\n" % (command_name, argument[0], argument[1]) | ||
| 60 | help_string += " \x02Syntax:\x02 {0:{2}} - {1}\n" % (command_name+' '+argument[0], argument[1], width) | ||
| 61 | #help_string += " \x02Syntax:\x02 %s %s - %s\n" % (command_name, argument[0], argument[1]) | ||
| 56 | 62 | else: | |
| 57 | help_string += " \x02Syntax:\x02 %s %s\n" % (command_name, argument) | ||
| 63 | help_string += " \x02Syntax:\x02 {0} {1}\n" % (command_name, argument) | ||
| 64 | #help_string += " \x02Syntax:\x02 %s %s\n" % (command_name, argument) | ||
| 58 | 65 | else: | |
| 59 | 66 | help_string += " \x02Syntax:\x02 %s\n" % command_name | |
| 60 | help_string += " \x02Description:\x02 %s\n" % command_description | ||
| 61 | help_string += " \x02Minimum level:\x02 %d\n" % command_level | ||
| 67 | if command_description: | ||
| 68 | help_string += " \x02Description:\x02 %s\n" % command_description | ||
| 69 | if command_level: | ||
| 70 | help_string += " \x02Minimum level:\x02 %d\n" % command_level | ||
| 62 | 71 | self.respond(server, sender, target, help_string) | |
| 63 | 72 | elif command_name == 'alias': | |
| 64 | 73 | help_string = "Aliases defined at this point is\n" | |
| … | … | ||
| 79 | 79 | help_string = "The following modules are currently loaded: %s" % ", ".join(self.module_list) | |
| 80 | 80 | help_string += "\nThe following modules can be loaded: %s" % ", ".join([m for m in self.found_modules if m not in self.module_list]) | |
| 81 | 81 | self.respond(server, sender, target, help_string) | |
| 82 | elif command_name == 'commands': | ||
| 83 | commands = [] | ||
| 84 | for command_name, command in self.globals.bot_commands.iteritems(): | ||
| 85 | command_level = command.get('level', 0) | ||
| 86 | if sender_level >= command_level: | ||
| 87 | commands.append(command_name) | ||
| 88 | help_string = "The following commands are available: %s" % ", ".join(commands) | ||
| 89 | self.respond(server, sender, target, help_string) | ||
| 82 | 90 | else: | |
| 83 | 91 | self.respond(server, sender, target, "There is no \x02%s\x02 command." % command_name) | |
| 92 | |||
| 93 | def get_first(tos): | ||
| 94 | if type(tos) is tuple or type(tos) is list: | ||
| 95 | return tos[0] | ||
| 96 | else: | ||
| 97 | return tos | ||
| 84 | 98 | ||
| 85 | 99 | def do_general_help(self, server, sender, target, sender_level): | |
| 86 | 100 | help_string = "The commands availible are:\n" | |
| 101 | width = [] | ||
| 102 | print " + Figure out width." | ||
| 103 | for cn, c in self.globals.bot_commands.iteritems(): | ||
| 104 | alw = [] | ||
| 105 | al = c.get('arguments', ()) | ||
| 106 | if type(al) is not list: al = [al] | ||
| 107 | for a in al: | ||
| 108 | if a: | ||
| 109 | if type(a) is not tuple: a = (a, "") | ||
| 110 | alw.append(len(a[0])) | ||
| 111 | if alw: width.append(len(cn)+max(alw)+3) | ||
| 112 | else: width.append(len(cn)) | ||
| 113 | if width: width = max(width) | ||
| 114 | else: width = 0 | ||
| 115 | print " + Width is %d." % width | ||
| 116 | |||
| 87 | 117 | for command_name, command in self.globals.bot_commands.iteritems(): | |
| 88 | 118 | command_arguments = command.get('arguments', "") | |
| 89 | 119 | if not type(command_arguments) is list: | |
| … | … | ||
| 134 | 134 | # | | |-Arguments for command | |
| 135 | 135 | # | |-Command name | |
| 136 | 136 | # |-Public command indicator | |
| 137 | help_string += "%(public)c\x02%(name)s\x02 %(argument)s %(space)s %(description)s %(space2)s %(level)s\n" % \ | ||
| 138 | {'public': (' ', '*')[command_public], # If command_public is False use first value in tuple. | ||
| 139 | 'name': command_name, | ||
| 140 | 'argument': argument, | ||
| 141 | 'space': " "*(30-(len(command_name)+len(argument))), | ||
| 142 | 'description': command_description, | ||
| 143 | 'space2': " "*(50-(len(command_description))), | ||
| 144 | 'level': ('(>'+str(command_level)+')', '')[command_level is 0]} | ||
| 137 | help_string += "{public}{namearg:{width}} - {description} {level}\n".format(\ | ||
| 138 | width = width, | ||
| 139 | public = (' ', '*')[command_public], | ||
| 140 | namearg = "\x02{0}\x02 {1}".format(command_name, argument), | ||
| 141 | description = command_description, | ||
| 142 | level = ('(>'+str(command_level)+')', '')[command_level is 0]) | ||
| 145 | 143 | help_string += "To see help for specific commands use \x02help command\x02." | |
| 146 | 144 | self.respond(server, sender, target, help_string) |
kofoo_mediawiki.py
(33 / 9)
|   | |||
| 23 | 23 | mediawiki_requires = ['webhelpers'] | |
| 24 | 24 | ||
| 25 | 25 | mediawiki_helpers = ['mw_add_to_page', | |
| 26 | 'mw_get_url', | ||
| 26 | 27 | 'mw_get_table', | |
| 27 | 28 | 'mw_get_list', | |
| 28 | 'mw_add_to_list', | ||
| 29 | 'mw_add_section', | ||
| 30 | 29 | 'mw_get_section_level', | |
| 31 | 30 | 'mw_get_section', | |
| 31 | 'mw_add_table', | ||
| 32 | 'mw_add_to_table', | ||
| 33 | 'mw_add_to_list', | ||
| 34 | 'mw_add_section', | ||
| 32 | 35 | 'mw_rewrite_wiki_links'] | |
| 33 | 36 | ||
| 34 | 37 | do_wiki_command = { 'description': "Do things to a wiki", | |
| 35 | 38 | 'long help': """\ | |
| 36 | """, | ||
| 37 | 'arguments': [("on <pagename> [in <sectionname>] add <Text to add>", | ||
| 38 | "Add text to a specific page on the wiki at the bottom of a specific section"), | ||
| 39 | ("add section <newsection> to <pagename> [below <parentsection>]", | ||
| 40 | "Add a section to a page")], | ||
| 39 | This is an wide command to do anything the mediawiki module can do with wikipages. | ||
| 40 | Things to take note of is that the 'add to page' and 'add section' command does not add | ||
| 41 | text to the top of the page if at top but instead add it at the bottom of the first | ||
| 42 | section.""", | ||
| 43 | 'arguments': [("get table|list|section \"<itemname>\" on \"<pagename>\"", "Get a named item from a page on the wiki"), | ||
| 44 | ("get url \"<pagename>\"", "Get URL to a specific page"), | ||
| 45 | ("search \"<term>\" [max: <max results>]", "Search titels in wiki for articles"), | ||
| 46 | ("add section \"<sectionname>\" [level <level>|below <parentsection>] on \"<pagename>\" [at top]", "Create a section on a page."), | ||
| 47 | ("add table \"<tablename>\" in \"<parentsection>\" on \"<pagename>\": \"<col1>\"[, \"<col2>\"[..]] [at top]", "Add a table to a section"), | ||
| 48 | ("add to list \"<listname>\" on \"<pagename>\": \"<item>\" [at top]", "Add an item to a list"), | ||
| 49 | ("add to table \"<tablename>\" on \"<pagename>\": \"<col1>\"[, \"<col2>\"[..]] [at top]", "Add a row to a table"), | ||
| 50 | ("add to section \"<sectionname>\" on \"<pagename>\": \"<new text>\" [at top]", "Add text to a section"), | ||
| 51 | ("add to page \"<pagename>\": \"<new text>\" [at top]", "Add text to a page")], | ||
| 41 | 52 | 'public': True, | |
| 42 | 53 | 'level': 70} | |
| 43 | 54 | ||
| … | … | ||
| 145 | 145 | bot.respond(server, sender, target, "\x02%s\x02 is not a valid argument or not enough arguments." % args[1]) | |
| 146 | 146 | return False | |
| 147 | 147 | elif args[0] == 'search' and args[1:]: | |
| 148 | m = re.match(r'([\"\']?)(.*?)\1', ' '.join(args[1:])) | ||
| 148 | m = re.match(r'([\"\']?)(.*?)\1(\smax: |)([0-9]+|)', ' '.join(args[1:])) | ||
| 149 | 149 | if m and m.group(2).strip(): | |
| 150 | 150 | search_terms = m.group(2) | |
| 151 | has_max = len(m.group(3)) > 0 | ||
| 152 | if has_max: | ||
| 153 | try: | ||
| 154 | result_max = max(int(m.group(4)), 1) | ||
| 155 | except Exception, e: | ||
| 156 | print " - Could not convert '%s' to integer." % m.group(4) | ||
| 157 | result_max = 1 | ||
| 158 | else: | ||
| 159 | result_max = 1 | ||
| 151 | 160 | if type(search_terms) is not unicode: | |
| 152 | 161 | if '\xc3' in search_terms: | |
| 153 | 162 | search_terms = search_terms.decode("utf-8") | |
| … | … | ||
| 165 | 165 | try: | |
| 166 | 166 | bot.respond(server, sender, target, "\x02Search results:\x02") | |
| 167 | 167 | results = [r['title'] for r in wiki_site.search(search_terms)] | |
| 168 | if not results: | ||
| 169 | print " - No results." | ||
| 170 | bot.respond(server, sender, target, "No results.") | ||
| 171 | return True | ||
| 168 | 172 | width = max([len(r.encode("latin-1")) for r in results]) | |
| 169 | for result in results: | ||
| 173 | for result in results[:result_max]: | ||
| 170 | 174 | url = mw_get_url(result) | |
| 171 | 175 | if url: | |
| 172 | 176 | res_string = " {0:{1}} : {2}".format(result.encode("latin-1"), width, url) |
kofoo_set.py
(1 / 2)
|   | |||
| 11 | 11 | 'long help': """\ | |
| 12 | 12 | Set values for configurations such as user access level.""", | |
| 13 | 13 | 'arguments': | |
| 14 | [("access <user> <newlevel>", "Set the new accesslevel for <user>."), | ||
| 15 | ("quit [quit message]", "Set a quit message.")], | ||
| 14 | [("access <user> <newlevel>", "Set the new accesslevel for <user>.")], | ||
| 16 | 15 | 'public': False, | |
| 17 | 16 | 'level': 50} | |
| 18 | 17 |

