ban he and also time

This commit is contained in:
iou1name 2018-01-23 18:40:08 -05:00
parent 7f819740a8
commit ce7e3fdddb
5 changed files with 79 additions and 16 deletions

View File

@ -2,7 +2,7 @@
import re import re
import formatting import formatting
from module import commands, priority, OP, HALFOP, require_privilege, require_chanmsg from module import commands, priority, OP, HALFOP, require_privilege, require_chanmsg, example
from tools import Identifier from tools import Identifier
@ -75,6 +75,7 @@ def ban(bot, trigger):
This give admins the ability to ban a user. This give admins the ability to ban a user.
The bot must be a Channel Operator for this command to work. The bot must be a Channel Operator for this command to work.
""" """
print(bot.privileges)
if bot.privileges[trigger.sender][bot.nick] < HALFOP: if bot.privileges[trigger.sender][bot.nick] < HALFOP:
return bot.reply("I'm not a channel operator!") return bot.reply("I'm not a channel operator!")
text = trigger.group().split() text = trigger.group().split()
@ -162,6 +163,7 @@ def kickban(bot, trigger):
@require_chanmsg @require_chanmsg
@require_privilege(OP, 'You are not a channel operator.') @require_privilege(OP, 'You are not a channel operator.')
@commands('topic') @commands('topic')
@example(".topic We're discussing penises, would you like to join?")
def topic(bot, trigger): def topic(bot, trigger):
""" """
This gives ops the ability to change the topic. This gives ops the ability to change the topic.

View File

@ -19,7 +19,7 @@ BRAIL_CHARS = "⠿⠾⠼⠸⠰⠠ "
HEADERS = {'User-Agent': 'Gimme ascii.'} HEADERS = {'User-Agent': 'Gimme ascii.'}
def scale_image(image, maxDim=100): def scale_image(image, maxDim=(100,100)):
""" """
Resizes an image while preserving the aspect ratio. Chooses the Resizes an image while preserving the aspect ratio. Chooses the
dimension to scale by based on whichever is larger, ensuring that dimension to scale by based on whichever is larger, ensuring that
@ -30,17 +30,17 @@ def scale_image(image, maxDim=100):
""" """
original_width, original_height = image.size original_width, original_height = image.size
original_width = original_width * 2 original_width = original_width * 2
if original_width <= maxDim and original_height <= maxDim: if original_width <= maxDim[0] and original_height <= maxDim[1]:
new_width, new_height = image.size new_width, new_height = image.size
elif original_width > original_height: elif original_width > original_height:
new_width = maxDim new_width = maxDim[0]
aspect_ratio = original_height/float(original_width) aspect_ratio = original_height/float(original_width)
new_height = int(aspect_ratio * new_width) new_height = int(aspect_ratio * new_width)
else: else:
new_height = maxDim new_height = maxDim[1]
aspect_ratio = original_width/float(original_height) aspect_ratio = original_width/float(original_height)
new_width = int(aspect_ratio * new_height) new_width = int(aspect_ratio * new_height)
image = image.resize((new_width, new_height), Image.ANTIALIAS) image = image.resize((new_width, new_height))
return image return image
@ -241,6 +241,7 @@ def ascii(bot, trigger):
parser.add_argument("-r", "--reverse", action="store_true", help="Reverse.") parser.add_argument("-r", "--reverse", action="store_true", help="Reverse.")
parser.add_argument("-c", "--color", action="store_true") parser.add_argument("-c", "--color", action="store_true")
parser.add_argument("-b", "--brail", action="store_true") parser.add_argument("-b", "--brail", action="store_true")
parser.add_argument("-B", "--brail2", action="store_true")
parser.add_argument("-a", "--animated", action="store_true") parser.add_argument("-a", "--animated", action="store_true")
parser.add_argument("-h", "--help", action="store_true") parser.add_argument("-h", "--help", action="store_true")
args = parser.parse_args(trigger.group(2).split()) args = parser.parse_args(trigger.group(2).split())
@ -264,11 +265,68 @@ def ascii(bot, trigger):
file = {"file": open("temp.png", "rb")} file = {"file": open("temp.png", "rb")}
res = requests.post("https://uguu.se/api.php?d=upload-tool", files=file) res = requests.post("https://uguu.se/api.php?d=upload-tool", files=file)
bot.say(res.text) bot.say(res.text)
elif args.brail2:
image = open_image(args.imagePath)
image_ascii = image_to_brail(image)
image_ascii = image_ascii.replace(""," ")
bot.say(image_ascii)
else: else:
image_ascii = image_to_ascii(None, **vars(args)) image_ascii = image_to_ascii(None, **vars(args))
bot.say(image_ascii) bot.say(image_ascii)
def brail_char(chunk, threshold):
"""
Accepts a numpy matrix and spits out a brail character.
"""
chunk = np.array_split(chunk, 3, axis=0)
chunk = np.concatenate(chunk, axis=1)
chunk = np.array_split(chunk, 6, axis=1)
dots = ""
for sub_chunk in chunk:
if np.mean(sub_chunk) < threshold:
dots += "1"
else:
dots += "0"
char = chr(int(dots, base=2)+10240)
return char
def image_to_brail(image, fontSize=(8,15)):
"""
An alternative method of generating brail ascii art.
"""
if not image:
image = open_image(kwargs["imagePath"])
if image.mode == "P":
image = image.convert(image.palette.mode)
if image.mode == "RGBA":
image = alpha_composite(image).convert("RGB")
image = image.convert("L")
matSize = (image.size[0] // fontSize[0], image.size[1] // fontSize[1])
if image.size[0] > fontSize[0]*100 or image.size[1] > fontSize[1]*100:
image = scale_image(image, (fontSize[0]*100, fontSize[1]*100))
image = image.crop((0, 0, matSize[0]*fontSize[0], matSize[1]*fontSize[1]))
threshold = np.mean(image)
grid = np.array(image)
grid = np.split(grid, matSize[1], axis=0)
grid = np.concatenate(grid, axis=1)
grid = np.split(grid, matSize[0]*matSize[1], axis=1)
for n, chunk in enumerate(grid):
char = brail_char(chunk, threshold)
grid[n] = char
grid = "".join(grid)
grid = [grid[n : n + matSize[0]] for n in range(0, len(grid), matSize[0])]
return "\n".join(grid)
if __name__=='__main__': if __name__=='__main__':
import argparse import argparse

View File

@ -6,7 +6,7 @@ ban he
""" """
import time import time
from module import commands, example from module import commands, example, require_admin
import modules.adminchannel import modules.adminchannel
@commands('banhe') @commands('banhe')
@ -41,15 +41,14 @@ def banhe(bot, trigger):
bot.say(f"Unbanned \x0304{banhee}\x03") bot.say(f"Unbanned \x0304{banhee}\x03")
@require_admin
@commands("banheall") @commands("banheall")
@example(".banheall")
def banheall(bot, trigger): def banheall(bot, trigger):
""" """
Ban them all, Johnny. Ban them all, Johnny.
""" """
if not trigger.admin:
return
period = trigger.group(2) period = trigger.group(2)
print(bot.nick)
trigger.set_nick(bot.nick) trigger.set_nick(bot.nick)
conv = {'s':1, 'm':60, 'h':3600, 'd':86400} conv = {'s':1, 'm':60, 'h':3600, 'd':86400}

View File

@ -116,7 +116,7 @@ def format_time(db=None, config=None, zone=None, nick=None, channel=None,
1. The format for the nick `nick` in `db`, if one is set and valid. 1. The format for the nick `nick` in `db`, if one is set and valid.
2. The format for the channel `channel` in `db`, if one is set and valid. 2. The format for the channel `channel` in `db`, if one is set and valid.
3. The default format in `config`, if one is set and valid. 3. The default format in `config`, if one iqqs set and valid.
4. ISO-8601 4. ISO-8601
If `db` is not given or is not set up, steps 1 and 2 are skipped. If config If `db` is not given or is not set up, steps 1 and 2 are skipped. If config
@ -161,16 +161,17 @@ def relativeTime(bot, nick, telldate):
nowdatetime = datetime.datetime.strptime(timenow, bot.config.core.default_time_format) nowdatetime = datetime.datetime.strptime(timenow, bot.config.core.default_time_format)
except ValueError: except ValueError:
return("Unable to parse relative time.") return("Unable to parse relative time.")
timediff = nowdatetime - telldatetime timediff = nowdatetime - telldatetime
reltime = [] reltime = []
# TODO: Rewrite all of this.
if timediff.days: if timediff.days:
if timediff.days // 365: if timediff.days // 365:
reltime.append( str(timediff.days // 365) + " year" ) reltime.append( str(timediff.days // 365) + " year" )
if timediff.days % 365 // 31: if timediff.days % 365 // 30:
reltime.append( str(timediff.days % 365 // 31) + " month") reltime.append( str(timediff.days % 365 // 30.416).partition(".")[0] + " month")
if timediff.days % 365 % 31: if timediff.days % 365 % 30:
reltime.append( str(timediff.days % 365 % 31) + " day") reltime.append( str(timediff.days % 365 % 30.416).partition(".")[0] + " day")
else: else:
if timediff.seconds // 3600: if timediff.seconds // 3600:

View File

@ -192,3 +192,6 @@ class Trigger(str):
"""Sets the trigger's group to something new.""" """Sets the trigger's group to something new."""
self._match = re.match("\..+", new_group) self._match = re.match("\..+", new_group)
self._group = self._match.group() self._group = self._match.group()
def set_admin(self, bool):
self._admin = bool