Created
March 12, 2016 23:00
-
-
Save cr5315/855d3e78c77c53c1e5b2 to your computer and use it in GitHub Desktop.
vend.py
This file contains hidden or 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 util.hook import * | |
from util import output | |
import random | |
# vend.py | |
# | |
# It vends! | |
# | |
# Version 2.0 | |
VEND_LIST = [] | |
VEND_SPECIAL = [] | |
def load(): | |
global VEND_LIST | |
global VEND_SPECIAL | |
VEND_LIST = [] | |
VEND_SPECIAL = [] | |
try: | |
with open("vendlist.txt", "r") as f: | |
for line in f: | |
VEND_LIST.append(line) | |
except IOError: | |
output.error("Unable to load vendlist.txt", "VEND") | |
VEND_LIST = [] | |
try: | |
with open("vendspecial.txt", "r") as g: | |
for line in g: | |
VEND_SPECIAL.append(line) | |
except IOError: | |
output.error("Unable to load vendspecial.txt", "VEND") | |
VEND_SPECIAL = [] | |
def setup(code): | |
load() | |
@hook(cmds=["vendreload"], admin=True) | |
def vend_reload(code, input): | |
load() | |
return code.reply("Vend lists reloaded.") | |
@hook(cmds=["vendcount"], rate=15) | |
def vend_count(code, input): | |
vendlistlen = len(VEND_LIST) | |
vendspeciallen = len(VEND_SPECIAL) | |
total = vendlistlen + vendspeciallen | |
code.reply("There are %d items in the vend list, and %d items in the special vend list, for a total of %d items." % | |
(vendlistlen, vendspeciallen, total)) | |
@hook(cmds=["vendrequest"], rate=15, args=True) | |
def vend_request(code, input): | |
user = input.nick | |
request = input.group(2) | |
with open("vendrequest.csv", "a") as f: | |
try: | |
f.write("%s, %s\n" % (user, request)) | |
code.reply("Request submitted") | |
except: | |
code.reply("There was a problem with your submission") | |
@hook(rule=r"^!.*end$", rate=15) | |
def end(code, input): | |
action = input.group()[1:] | |
if is_valid_vend(action): | |
msg = "%ss %s" % (action, vend(True)) | |
code.write(['PRIVMSG', input.sender, ' :\x01ACTION', msg, '\x01']) | |
@hook(cmds=["send"], rate=15) | |
def send(code, input): | |
if len(input.group().split()) > 1: | |
to = " ".join(input.group().split()[1:]) | |
else: | |
to = input.nick | |
msg = "sends %s to %s" % (vend(True), to) | |
code.write(['PRIVMSG', input.sender, ' :\x01ACTION', msg, '\x01']) | |
@hook(cmds=["append"], rate=15) | |
def append(code, input): | |
msg = "duct-tapes %s to %s" % (vend(False), vend(False)) | |
code.write(['PRIVMSG', input.sender, ' :\x01ACTION', msg, '\x01']) | |
def is_valid_vend(action): | |
exceptions = ["append", "send"] | |
if action.lower() in exceptions: | |
return False | |
if not action.isalpha(): | |
return False | |
if len(action) > 10: | |
return False | |
if not action.endswith("end"): | |
return False | |
return True | |
def vend(special=True): | |
if special: | |
if random.randint(1, 100) <= 25: | |
v = random.choice(VEND_SPECIAL) | |
if v == "some green text": | |
return "\x0303" + v + "\x03" | |
else: | |
return v | |
else: | |
return random.choice(VEND_LIST) | |
else: | |
return random.choice(VEND_LIST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment