Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: plugins/karma.py
This commit is contained in:
commit
0030669682
13 changed files with 256 additions and 186 deletions
|
@ -20,6 +20,9 @@ Before you can run the bot, you need to install a few Python dependencies. LXML
|
|||
These can be installed with `pip` (The Python package manager):
|
||||
|
||||
[sudo] pip install -r requirements.txt
|
||||
|
||||
If you use `pip`, you will also need the following packages on linux or `pip` will fail to install the requirements.
|
||||
```python, python-dev, libenchant-dev, libenchant1c2a, libxslt-dev, libxml2-dev.```
|
||||
|
||||
#### How to install `pip`
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from util import hook
|
||||
import os
|
||||
import os, sys
|
||||
import re
|
||||
import json
|
||||
import time
|
||||
|
@ -114,15 +114,18 @@ def stop(inp, nick=None, conn=None):
|
|||
|
||||
|
||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||
def restart(inp, nick=None, conn=None):
|
||||
def restart(inp, nick=None, conn=None, bot=None):
|
||||
"""restart [reason] -- Restarts the bot with [reason] as its quit message."""
|
||||
if inp:
|
||||
conn.cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)])
|
||||
else:
|
||||
conn.cmd("QUIT", ["Restarted by {}.".format(nick)])
|
||||
for botcon in bot.conns:
|
||||
if inp:
|
||||
bot.conns[botcon].cmd("QUIT", ["Restarted by {} ({})".format(nick, inp)])
|
||||
else:
|
||||
bot.conns[botcon].cmd("QUIT", ["Restarted by {}.".format(nick)])
|
||||
time.sleep(5)
|
||||
os.execl("./cloudbot", "cloudbot", "restart")
|
||||
|
||||
#os.execl("./cloudbot", "cloudbot", "restart")
|
||||
args = sys.argv[:]
|
||||
args.insert(0, sys.executable)
|
||||
os.execv(sys.executable, args)
|
||||
|
||||
@hook.command(autohelp=False, permissions=["botcontrol"])
|
||||
def clearlogs(inp, input=None):
|
||||
|
|
|
@ -5,18 +5,6 @@ with open("plugins/data/larts.txt") as f:
|
|||
larts = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
||||
with open("plugins/data/slaps.txt") as f:
|
||||
slaps = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
||||
with open("plugins/data/slap_items.txt") as f:
|
||||
items = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
||||
with open("plugins/data/kills.txt") as f:
|
||||
kills = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
||||
with open("plugins/data/insults.txt") as f:
|
||||
insults = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
@ -25,27 +13,6 @@ with open("plugins/data/flirts.txt") as f:
|
|||
flirts = [line.strip() for line in f.readlines()
|
||||
if not line.startswith("//")]
|
||||
|
||||
|
||||
@hook.command
|
||||
def slap(inp, me=None, nick=None, conn=None, notice=None):
|
||||
"""slap <user> -- Makes the bot slap <user>."""
|
||||
target = inp.strip()
|
||||
|
||||
if " " in target:
|
||||
notice("Invalid username!")
|
||||
return
|
||||
|
||||
# if the user is trying to make the bot slap itself, slap them
|
||||
if target.lower() == conn.nick.lower() or target.lower() == "itself":
|
||||
target = nick
|
||||
|
||||
values = {"item": random.choice(items), "user": target}
|
||||
phrase = random.choice(slaps)
|
||||
|
||||
# act out the message
|
||||
me(phrase.format(**values))
|
||||
|
||||
|
||||
@hook.command
|
||||
def lart(inp, me=None, nick=None, conn=None, notice=None):
|
||||
"""lart <user> -- LARTs <user>."""
|
||||
|
@ -66,26 +33,6 @@ def lart(inp, me=None, nick=None, conn=None, notice=None):
|
|||
me(phrase.format(**values))
|
||||
|
||||
|
||||
@hook.command
|
||||
def kill(inp, me=None, nick=None, conn=None, notice=None):
|
||||
"""kill <user> -- Makes the bot kill <user>."""
|
||||
target = inp.strip()
|
||||
|
||||
if " " in target:
|
||||
notice("Invalid username!")
|
||||
return
|
||||
|
||||
# if the user is trying to make the bot slap itself, slap them
|
||||
if target.lower() == conn.nick.lower() or target.lower() == "itself":
|
||||
target = nick
|
||||
|
||||
values = {"user": target}
|
||||
phrase = random.choice(kills)
|
||||
|
||||
# act out the message
|
||||
me(phrase.format(**values))
|
||||
|
||||
|
||||
@hook.command
|
||||
def insult(inp, nick=None, me=None, conn=None, notice=None):
|
||||
"""insult <user> -- Makes the bot insult <user>."""
|
||||
|
|
79
plugins/data/kills.json
Normal file
79
plugins/data/kills.json
Normal file
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"templates":[
|
||||
"rips off {user}'s {limbs} and leaves them to die.",
|
||||
"grabs {user}'s head and rips it clean off their body.",
|
||||
"grabs a {gun} and riddles {user}'s body with bullets.",
|
||||
"gags and ties {user} then throws them off a {tall_thing}.",
|
||||
"crushes {user} with a huge spiked {spiked_thing}.",
|
||||
"glares at {user} until they die of boredom.",
|
||||
"stabs {user} in the heart a few times with a {weapon_stab}.",
|
||||
"rams a {weapon_explosive} up {user}'s ass and lets off a few rounds.",
|
||||
"crushes {user}'s skull in with a {weapon_crush}.",
|
||||
"unleashes the armies of Isengard on {user}.",
|
||||
"gags and ties {user} then throws them off a {tall_thing} to their death.",
|
||||
"reaches out and punches right through {user}'s chest.",
|
||||
"slices {user}'s limbs off with a {weapon_slice}.",
|
||||
"throws {user} to Cthulu and watches them get ripped to shreds.",
|
||||
"feeds {user} to an owlbear who then proceeds to maul them violently.",
|
||||
"turns {user} into a snail and covers then in salt.",
|
||||
"snacks on {user}'s dismembered body.",
|
||||
"stuffs {bomb} up {user}'s ass and waits for it to go off.",
|
||||
"puts {user} into a sack, throws the sack in the river, and hurls the river into space.",
|
||||
"goes bowling with {user}'s bloody disembodied head.",
|
||||
"sends {user} to /dev/null!",
|
||||
"feeds {user} coke and mentos till they violently explode."
|
||||
],
|
||||
"parts": {
|
||||
"gun":[
|
||||
"AK47",
|
||||
"machine gun",
|
||||
"automatic pistol",
|
||||
"Uzi"
|
||||
],
|
||||
"limbs": [
|
||||
"legs",
|
||||
"arms",
|
||||
"limbs"
|
||||
],
|
||||
"weapon_stab": [
|
||||
"knife",
|
||||
"shard of glass",
|
||||
"sword blade",
|
||||
"butchers knife",
|
||||
"corkscrew"
|
||||
],
|
||||
"weapon_slice": [
|
||||
"sharpened katana",
|
||||
"chainsaw",
|
||||
"polished axe"
|
||||
],
|
||||
"weapon_crush": [
|
||||
"spiked mace",
|
||||
"baseball bat",
|
||||
"wooden club",
|
||||
"massive steel ball",
|
||||
"heavy iron rod"
|
||||
],
|
||||
"weapon_explosive": [
|
||||
"rocket launcher",
|
||||
"grenade launcher",
|
||||
"napalm launcher"
|
||||
],
|
||||
"tall_thing": [
|
||||
"bridge",
|
||||
"tall building",
|
||||
"cliff",
|
||||
"mountain"
|
||||
],
|
||||
"spiked_thing": [
|
||||
"boulder",
|
||||
"rock",
|
||||
"barrel of rocks"
|
||||
],
|
||||
"bomb": [
|
||||
"a bomb",
|
||||
"some TNT",
|
||||
"a bunch of C4"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
cast iron skillet
|
||||
large trout
|
||||
baseball bat
|
||||
wooden cane
|
||||
nail
|
||||
printer
|
||||
shovel
|
||||
pair of trousers
|
||||
CRT monitor
|
||||
diamond sword
|
||||
baguette
|
||||
physics textbook
|
||||
television
|
||||
mau5head
|
||||
five ton truck
|
||||
roll of duct tape
|
||||
book
|
||||
laptop
|
||||
old television
|
||||
sack of rocks
|
||||
rainbow trout
|
||||
cobblestone block
|
||||
lava bucket
|
||||
rubber chicken
|
||||
spiked bat
|
||||
gold block
|
||||
fire extinguisher
|
||||
heavy rock
|
||||
chunk of dirt
|
62
plugins/data/slaps.json
Normal file
62
plugins/data/slaps.json
Normal file
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"templates":[
|
||||
"{hits} {user} with a {item}.",
|
||||
"{hits} {user} around a bit with a {item}.",
|
||||
"{throws} a {item} at {user}.",
|
||||
"{throws} a few {item}s at {user}.",
|
||||
"grabs a {item} and {throws} it in {user}'s face.",
|
||||
"launches a {item} in {user}'s general direction.",
|
||||
"sits on {user}'s face while slamming a {item} into their crotch.",
|
||||
"starts slapping {user} silly with a {item}.",
|
||||
"holds {user} down and repeatedly {hits} them with a {item}.",
|
||||
"prods {user} with a {item}.",
|
||||
"picks up a {item} and {hits} {user} with it.",
|
||||
"ties {user} to a chair and {throws} a {item} at them.",
|
||||
"{hits} {user} on the head with a {item}.",
|
||||
"ties {user} to a pole and whips them with a {item}."
|
||||
],
|
||||
"parts": {
|
||||
"item":[
|
||||
"cast iron skillet",
|
||||
"large trout",
|
||||
"baseball bat",
|
||||
"wooden cane",
|
||||
"nail",
|
||||
"printer",
|
||||
"shovel",
|
||||
"pair of trousers",
|
||||
"CRT monitor",
|
||||
"diamond sword",
|
||||
"baguette",
|
||||
"physics textbook",
|
||||
"television",
|
||||
"mau5head",
|
||||
"five ton truck",
|
||||
"roll of duct tape",
|
||||
"book",
|
||||
"laptop",
|
||||
"old television",
|
||||
"sack of rocks",
|
||||
"rainbow trout",
|
||||
"cobblestone block",
|
||||
"lava bucket",
|
||||
"rubber chicken",
|
||||
"spiked bat",
|
||||
"gold block",
|
||||
"fire extinguisher",
|
||||
"heavy rock",
|
||||
"chunk of dirt"
|
||||
],
|
||||
"throws": [
|
||||
"throws",
|
||||
"flings",
|
||||
"chucks"
|
||||
],
|
||||
"hits": [
|
||||
"hits",
|
||||
"whacks",
|
||||
"slaps",
|
||||
"smacks"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
slaps {user} with a {item}.
|
||||
slaps {user} around a bit with a {item}.
|
||||
throws a {item} at {user}.
|
||||
chucks a few {item}s at {user}.
|
||||
grabs a {item} and throws it in {user}'s face.
|
||||
launches a {item} in {user}'s general direction.
|
||||
sits on {user}'s face while slamming a {item} into their crotch.
|
||||
starts slapping {user} silly with a {item}.
|
||||
holds {user} down and repeatedly whacks them with a {item}.
|
||||
prods {user} with a flaming {item}.
|
||||
picks up a {item} and whacks {user} with it.
|
||||
ties {user} to a chair and throws a {item} at them.
|
||||
hits {user} on the head with a {item}.
|
||||
ties {user} to a pole and whips them with a {item}.
|
|
@ -40,7 +40,7 @@ def define(inp):
|
|||
for article in sections:
|
||||
result += article[0]
|
||||
if len(article) > 2:
|
||||
result += ' '.join('{}. {}'.format(n + 1, section)
|
||||
result += u' '.join(u'{}. {}'.format(n + 1, section)
|
||||
for n, section in enumerate(article[1:]))
|
||||
else:
|
||||
result += article[1] + ' '
|
||||
|
|
|
@ -38,10 +38,10 @@ def down(db, nick_vote):
|
|||
def allowed(db, nick, nick_vote):
|
||||
time_restriction = 3600
|
||||
db.execute("""DELETE FROM karma_voters WHERE ? - epoch >= 3600""",
|
||||
(time.time(),))
|
||||
(time.time(),))
|
||||
db.commit()
|
||||
check = db.execute("""SELECT epoch FROM karma_voters WHERE voter=? AND votee=?""",
|
||||
(nick.lower(), nick_vote.lower())).fetchone()
|
||||
(nick.lower(), nick_vote.lower())).fetchone()
|
||||
|
||||
if check:
|
||||
check = check[0]
|
||||
|
@ -53,7 +53,7 @@ def allowed(db, nick, nick_vote):
|
|||
db.commit()
|
||||
return True, 0
|
||||
else:
|
||||
return False, timesince.timeuntil(check, now=time.time() - time_restriction)
|
||||
return False, timesince.timeuntil(check, now=time.time()-time_restriction)
|
||||
else:
|
||||
db.execute("""INSERT OR REPLACE INTO karma_voters(
|
||||
voter,
|
||||
|
@ -68,9 +68,9 @@ def allowed(db, nick, nick_vote):
|
|||
# karma_re = ('((\S+)(\+\+|\-\-))+', re.I)
|
||||
karma_re = ('(.+)(\+\+|\-\-)$', re.I)
|
||||
|
||||
|
||||
@hook.regex(*karma_re)
|
||||
def karma_add(match, nick='', chan='', db=None, notice=None):
|
||||
|
||||
if not db_ready:
|
||||
db_init(db)
|
||||
|
||||
|
@ -88,15 +88,15 @@ def karma_add(match, nick='', chan='', db=None, notice=None):
|
|||
nick_vote,
|
||||
up_karma,
|
||||
down_karma,
|
||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(), 0, 0, 0))
|
||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(),0,0,0))
|
||||
up(db, nick_vote)
|
||||
notice("Gave {} +1 karma!".format(nick_vote))
|
||||
notice("Gave {} 1 karma!".format(nick_vote))
|
||||
if match.group(2) == '--':
|
||||
db.execute("""INSERT or IGNORE INTO karma(
|
||||
nick_vote,
|
||||
up_karma,
|
||||
down_karma,
|
||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(), 0, 0, 0))
|
||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(),0,0,0))
|
||||
down(db, nick_vote)
|
||||
notice("Took away 1 karma from {}.".format(nick_vote))
|
||||
else:
|
||||
|
@ -120,32 +120,12 @@ def karma(inp, nick='', chan='', db=None):
|
|||
|
||||
nick_vote = inp
|
||||
out = db.execute("""SELECT * FROM karma WHERE nick_vote=?""",
|
||||
(nick_vote.lower(),)).fetchall()
|
||||
(nick_vote.lower(),)).fetchall()
|
||||
|
||||
if not out:
|
||||
return "That user has no karma."
|
||||
else:
|
||||
out = out[0]
|
||||
return "%s has \x02%s\x02 karma." % (nick_vote, out[1] - out[2])
|
||||
return "{} has {} karma points.".format(nick_vote, out[1]-out[2])
|
||||
|
||||
|
||||
@hook.command('dk')
|
||||
@hook.command
|
||||
def dkarma(inp, nick='', chan='', db=None):
|
||||
"""k/karma <nick> -- returns karma stats for <nick> in epeen."""
|
||||
|
||||
if not db_ready:
|
||||
db_init(db)
|
||||
|
||||
if not chan.startswith('#'):
|
||||
return
|
||||
|
||||
nick_vote = inp
|
||||
out = db.execute("""SELECT * FROM karma WHERE nick_vote=?""",
|
||||
(nick_vote.lower(),)).fetchall()
|
||||
|
||||
if not out:
|
||||
return "Vaginal karma detected."
|
||||
else:
|
||||
out = out[0]
|
||||
return "{}'s epnis is \x02{}\x02cm long.".format(nick_vote, out[1] - out[2])
|
||||
return
|
||||
|
|
|
@ -1,59 +1,21 @@
|
|||
# Plugin by Lukeroge
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import os
|
||||
from util import hook
|
||||
from util.text import get_text_list
|
||||
from util import hook, text, textgen
|
||||
import json, os
|
||||
|
||||
|
||||
TEMPLATE_RE = re.compile(r"\{(.+?)\}")
|
||||
GEN_DIR = "./plugins/data/name_files/"
|
||||
|
||||
|
||||
def get_generator(_json):
|
||||
data = json.loads(_json)
|
||||
return NameGenerator(data["name"], data["templates"],
|
||||
data["default_templates"], data["parts"])
|
||||
|
||||
|
||||
class NameGenerator(object):
|
||||
def __init__(self, name, templates, default_templates, parts):
|
||||
self.name = name
|
||||
self.templates = templates
|
||||
self.default_templates = default_templates
|
||||
self.parts = parts
|
||||
|
||||
def generate_name(self, template=None):
|
||||
"""
|
||||
Generates one name using the specified templates.
|
||||
If no templates are specified, use a random template from the default_templates list.
|
||||
"""
|
||||
name = self.templates[template or random.choice(self.default_templates)]
|
||||
|
||||
# get a list of all name parts we need
|
||||
name_parts = TEMPLATE_RE.findall(name)
|
||||
|
||||
for name_part in name_parts:
|
||||
part = random.choice(self.parts[name_part])
|
||||
name = name.replace("\{{}\}".format(name_part), part)
|
||||
|
||||
return name
|
||||
|
||||
def generate_names(self, amount):
|
||||
names = []
|
||||
for i in xrange(amount):
|
||||
names.append(self.generate_name())
|
||||
return names
|
||||
|
||||
def get_template(self, template):
|
||||
return self.templates[template]
|
||||
return textgen.TextGenerator(data["name"], data["templates"],
|
||||
data["parts"], data["default_templates"])
|
||||
|
||||
|
||||
@hook.command(autohelp=False)
|
||||
def namegen(inp, notice=None):
|
||||
"""namegen [generator] -- Generates some names using the chosen generator.
|
||||
'namegen list' will display a list of all generators."""
|
||||
"namegen [generator] -- Generates some names using the chosen generator. " \
|
||||
"'namegen list' will display a list of all generators."
|
||||
|
||||
# clean up the input
|
||||
inp = inp.strip().lower()
|
||||
|
@ -69,7 +31,7 @@ def namegen(inp, notice=None):
|
|||
# command to return a list of all available generators
|
||||
if inp == "list":
|
||||
message = "Available generators: "
|
||||
message += get_text_list(all_modules, 'and')
|
||||
message += text.get_text_list(all_modules, 'and')
|
||||
notice(message)
|
||||
return
|
||||
|
||||
|
@ -91,7 +53,7 @@ def namegen(inp, notice=None):
|
|||
return "Unable to read name file: {}".format(error)
|
||||
|
||||
# time to generate some names
|
||||
name_list = generator.generate_names(10)
|
||||
name_list = generator.generate_strings(10)
|
||||
|
||||
# and finally return the final message :D
|
||||
return "Some names to ponder: {}.".format(get_text_list(name_list, 'and'))
|
||||
return "Some names to ponder: {}.".format(text.get_text_list(name_list, 'and'))
|
||||
|
|
32
plugins/slap.py
Normal file
32
plugins/slap.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from util import hook, textgen
|
||||
import json
|
||||
|
||||
|
||||
def get_generator(_json, variables):
|
||||
data = json.loads(_json)
|
||||
return textgen.TextGenerator(data["templates"],
|
||||
data["parts"], variables=variables)
|
||||
|
||||
|
||||
@hook.command
|
||||
def slap(inp, me=None, nick=None, conn=None, notice=None):
|
||||
"""slap <user> -- Makes the bot slap <user>."""
|
||||
target = inp.strip()
|
||||
|
||||
if " " in target:
|
||||
notice("Invalid username!")
|
||||
return
|
||||
|
||||
# if the user is trying to make the bot slap itself, slap them
|
||||
if target.lower() == conn.nick.lower() or target.lower() == "itself":
|
||||
target = nick
|
||||
|
||||
variables = {
|
||||
"user": target
|
||||
}
|
||||
|
||||
with open("plugins/data/slaps.json") as f:
|
||||
generator = get_generator(f.read(), variables)
|
||||
|
||||
# act out the message
|
||||
me(generator.generate_string())
|
45
plugins/util/textgen.py
Normal file
45
plugins/util/textgen.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import re
|
||||
import random
|
||||
|
||||
TEMPLATE_RE = re.compile(r"\{(.+?)\}")
|
||||
|
||||
|
||||
class TextGenerator(object):
|
||||
def __init__(self, templates, parts, default_templates=None, variables=None):
|
||||
self.templates = templates
|
||||
self.default_templates = default_templates
|
||||
self.parts = parts
|
||||
self.variables = variables
|
||||
print self.variables
|
||||
|
||||
def generate_string(self, template=None):
|
||||
"""
|
||||
Generates one string using the specified templates.
|
||||
If no templates are specified, use a random template from the default_templates list.
|
||||
"""
|
||||
if self.default_templates:
|
||||
text = self.templates[template or random.choice(self.default_templates)]
|
||||
else:
|
||||
text = random.choice(self.templates)
|
||||
|
||||
if self.variables:
|
||||
for key, value in self.variables.items():
|
||||
text = text.replace("{%s}" % key, value)
|
||||
|
||||
# get a list of all text parts we need
|
||||
required_parts = TEMPLATE_RE.findall(text)
|
||||
|
||||
for required_part in required_parts:
|
||||
part = random.choice(self.parts[required_part])
|
||||
text = text.replace("{%s}" % required_part, part)
|
||||
|
||||
return text
|
||||
|
||||
def generate_strings(self, amount, template=None):
|
||||
strings = []
|
||||
for i in xrange(amount):
|
||||
strings.append(self.generate_string())
|
||||
return strings
|
||||
|
||||
def get_template(self, template):
|
||||
return self.templates[template]
|
|
@ -1,16 +1,16 @@
|
|||
from util import hook, http, web
|
||||
import json
|
||||
from urllib2 import HTTPError
|
||||
import urllib2
|
||||
|
||||
|
||||
def get_sound_info(game, search):
|
||||
search = search.replace(" ", "+")
|
||||
try:
|
||||
data = http.get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search))
|
||||
except HTTPError as e:
|
||||
data = http.get_json("http://p2sounds.blha303.com.au/search/%s/%s?format=json" % (game, search))
|
||||
except urllib2.HTTPError as e:
|
||||
return "Error: " + json.loads(e.read())["error"]
|
||||
items = []
|
||||
for item in data:
|
||||
for item in data["items"]:
|
||||
if "music" in game:
|
||||
textsplit = item["text"].split('"')
|
||||
text = ""
|
Reference in a new issue