This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
commandlist = {} | |
for module in os.listdir(os.path.dirname(__file__)): | |
if module == '__init__.py' or module[-3:] != '.py': | |
continue | |
__import__(module[:-3], locals(), globals()) | |
name = 'tools.'+module[:-3] | |
print "Importing "+name+"..." | |
try: | |
commands = getattr(sys.modules[name], 'commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import random | |
class Die: | |
def __init__(self,sides): | |
self.sides = sides | |
self.facet = False | |
def __str__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
regex = { | |
'prefix' : re.compile("^:(?P<nick>.+)(?:!(?P<user>.+))(?:@(?P<host>.+))") | |
} | |
def read_message (message): | |
""" | |
Turn an IRC message into an object | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example_arguments = ["arg1 arg2", "arg1 arg2 :Long argument with spaces in", ":Long argument with spaces in"] | |
if arguments[-1][0] == ':': | |
message = arguments[-1] | |
arguments = arguments[:-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instructions | |
- Restricted commands may only be done by admins, on quotes that belong to the user or on quotes about the user | |
- Gender | |
- Set gender: Set the users gender in the database | |
- "(?=I am|My gender is) (male|female|androgynous)", "Refer to me (by name|randomly)", "Refer to me with <list of five pronouns>" | |
- "{nick}: I am no refering to you with the pronouns <list of five pronouns>" | |
- Get gender: Ask the bot if the user has get a gender | |
- "What is my gender?", "What gender is (?P<person>.+)? | |
- "You are {gender}", "Person is {gender}" | |
- Aliases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
class Event (object): | |
message = re.compile("^(?::(?P<prefix>\S+) )?(?P<command>\w+|\d\d\d) (?P<params>.+)$") | |
def __new__ (cls, line, **kwargs): | |
message = cls.message.search(line) | |
if message: | |
prefix, command, params = message.groups() | |
print prefix, command, params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Parses incoming IRC messages, and formats outgoing IRC messages. | |
""" | |
def parse_message (string): | |
""" Parse an IRC message in the form: | |
[:{source} ]{command}[ parameters][ :{trailing}] | |
""" | |
# Default variables for parameters and trailing, | |
# as it is possible neither will be assigned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
`argumented` provides a way of 'multiplying' functions - usually test cases - | |
allowing them to be called with multiple argument sets and still appear as | |
seperate test cases. | |
In the following example, each of the test cases would be replaced with two test | |
cases, each of which would call the test case with the given arguments. | |
`@argument(*args, **kwargs)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Includes commands for multi-version python packages | |
# Ignore the commands you don't need :) | |
# Run tests | |
nosetests | |
# Create python package | |
python setup.py sdist upload | |
sudo python setup.py install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mongoengine import * | |
class QuerySetProperty(object): | |
"""A set of documents belonging to an entity from another collection | |
Basically, provides the functionality a backref would provide.""" | |
def __init__(self, cls): | |
self.cls = cls | |
def __get__(self, instance, owner): |
OlderNewer