def Send(chatroom, sender=None, name='random', top='_', bot='_', font='impact', img=''): if name == 'random': rand = GetRandomTemplate(chatroom, sender) name = rand[0] img = rand[1] elif name == "custom": if IsEmpty(img): raise Exception("img is empty") else: if IsEmpty(img): img = GetImg(chatroom, sender, name) if IsEmpty(img): if name not in builtinTemplates: chatroom.SendText("[Command(Meme)] Template named '" + name + "' not found") return CommandResult.Done() else: name = "custom" top = Escape(top) bot = Escape(bot) if IsEmpty2(top) and IsEmpty2(bot) and not IsEmpty(img): return CommandResult(images=Image(client=chatroom.client, url=img)) url = GetUrl(name, top, bot, font, img) return CommandResult( images=Image(client=chatroom.client, url="https://" + url))
def Done(self, done=True): if self.room.phase != RoomPhase.guessing: self.SendText("It's not time yet") return CommandResult.Failed() with self.lock: if self.pendingScore: self.SendText("You have done-ed") else: with self.room.lock: if len(self.room.losers) <= 1: self.SendText("You're the last one") elif self.pendingScore: self.SendText("You have done-ed") else: self.pendingScore = max( 0, round( (self.room.end - time()) * self.room.winPoint)) if not self.pendingScore: self.SendText("Time's up") else: if self in self.room.losers: self.room.losers.remove(self) if self not in self.room.winners: self.room.winners.append(self) self.room.winners.sort(key=lambda x: x.score, reverse=True) self.room.SendText("%s says he knows the answer." % self.name) if len(self.room.losers) <= 1: with self.room.cond: self.room.cond.notifyAll() return CommandResult.Done() return CommandResult.Failed()
def Start(self): with self.lock: if len(self.players) < 2: self.SendText("Need at least 2 players to start") return CommandResult.Failed() self.phase = RoomPhase.starting self.round = 0 self.obj.client.Thread(self.RoundStart) return CommandResult.Done()
def Stop(self, force=False): with self.lock: if self.nums: s = " ".join(FloatToStr(x) for x in self.nums) s2 = Solve(s) if s2: self.SendText(s2) else: send.SendText("Theres no solution to '%s'" % s) self.nums = None return CommandResult.Done()
def Solve(self, text): with self.lock: if self.nums: self.SendText( "Game is still running. Please stop it first if you want to solve. If the four numbers were also from me, just type '/24 next' to change the numbers and also give the answer" ) return CommandResult.Failed() s = Solve(text) if s: self.SendText(s) return CommandResult.Done()
def Stop(self, force=False): if not force: t = self.CheckTime() if t: self.SendText("You have to wait %d seconds" % t) return CommandResult.Failed() with self.lock: if self.nums: s = " ".join(FloatToStr(x) for x in self.nums) s2 = Solve(s) self.SendText(s2) self.nums = None return CommandResult.Done()
def Join(self, player): with self.lock: if player in self.playersByObj: player = self.playersByObj[player] if player in self.leavings: self.leavings.remove(player) player.SendText( "You have canceled to leave the next round") return CommandResult.Done() else: player.SendText( "Either you have already joined or waiting for the next round to join." ) return CommandResult.Failed() player = Player(self, player) if self.running: self.SendText( "%s, the game is currently running. You will automatically join the next round if any." % player.name) else: self.AddWaitingPlayers() return CommandResult.Done()
def Send(self): if self.nums: buts = Buttons(" ".join(FloatToStr(x) for x in self.nums)) buts.AddButton( "Next", "/24 next", "\nTo give up and ask for next numbers, type '/24 next'") buts.AddButton("Stop", "/24 stop", "\nTo just give up, type '/24 stop'") else: buts = Buttons("Game is not running") buts.AddButton("Create", "/24 create", "\nTo run it, type '/24 create'") self.SendButtons(buts) return CommandResult.Done()
def CommandList(message, options, text='', admin=False): client = message.client if admin: if client.hasAdminCommands: l = sorted([x for x in client._1adminCommands.items()]) s = 'Admin commands :' for k, v in l: si = "\n%s" % k if k != v.name: si = si + (" (%s)" % v.name) s = s + si return CommandResult.Done(texts=[s]) return CommandResult.Done(texts=['No admin command registered']) elif client.hasCommands: l = sorted([x for x in client._1commands.items()]) s = 'Commands :' for k, v in l: si = "\n%s" % k if k != v.name: si = si + (" (%s)" % v.name) s = s + si return CommandResult.Done(texts=[s]) return CommandResult.Done(texts=['No command registered'])
def JPEG(message, options, images=[], quality=50, iterations=50): img = images[0].bytes imgIn = BytesIO(img) baseQuality=quality for i in range(0, iterations): #open previously generated file compImg = PILImage.open(imgIn) #compress file at 50% of previous quality imgOut = BytesIO() compImg.save(imgOut, "JPEG", quality=quality) quality = int(quality*baseQuality/100) imgIn = imgOut imgIn.seek(0) img = imgIn.read() img = Image(bytes=img) return CommandResult.Done(images=[img])
def DeepArtCustom(message, images): s = Session() print("Getting token ...") rToken = s.get(daLoginUrl, verify=False) mToken = daTokenRx.match(rToken.text) token = mToken.group(1) print("Logging in ...") info = {'csrfmiddlewaretoken': token, 'email': daEmail, 'password': daPw} rLogin = s.post(daLoginUrl, verify=False) print("Uploading image ...") img = images[1].bytes rImg = s.post(daContentUploadUrl, files={'image': img}, verify=False) jImg = loads(rImg.text) print("Uploading style ...") style = images[0].bytes rStyle = s.post(daStyleUploadUrl, files={'image': style}, verify=False) jStyle = loads(rStyle.text) print("Requesting ...") info = { 'content_img': jImg['hash'], 'style_img': jStyle['hash'], 'email': daEmail, 'password': daPw, 'privacy': 'private' } rDa = s.post(daUrl, data=info, verify=False) jDa = loads(rDa.text) rDa = s.post(daHomeUrl + jDa['redirect'], verify=False) mDaCode = daCodeRx.match(rDa.text) daCode = mDaCode.group(1) daCodeUrl = daHost + daCode + "/" message.ReplyText("[DeepArt] Please wait up to 15 minutes.\n" + daCodeUrl) while True: rDaCode = s.get(daCodeUrl, verify=False) if rDaCode.url == daCodeUrl: mDaImg = daImgRx.match(rDaCode.text) daImg = mDaImg.group(1) img = Image(url=daImg) return CommandResult.Done(images=[img]) sleep(5)
def RObj(message, options, text=''): if not message.client.hasUser or not message.client.hasOA or not message.client.oAClient.obj: message.ReplyText("Sorry, this feature is unavailable") return CommandResult.Failed() client = message.client chatroom = message.chatroom sender = message.sender if chatroom.chatroomType == ChatroomType.user: message.ReplyText("This is a private chat") return CommandResult.Failed() if groupOnly and chatroom.chatroomType == ChatroomType.room: message.ReplyText("This needs to be a group") return CommandResult.Failed() if not sender or not sender.name: message.ReplyText("Sorry, we can't identify you") return CommandResult.Failed() if not chatroom.hasUser: message.ReplyText("You need to have our User Account Bot here.") return CommandResult.Failed() members = chatroom.members if len(members) == 0: message.ReplyText("Sorry, we couldn't get member list") return CommandResult.Failed() if client.oAClient.obj not in members: message.ReplyText( "Our Official Account Bot is not here. I'll try to invite it. Please retry after it joined" ) #\n%s\n%s" % (members, client.oAClient.obj)) try: chatroom.Invite(client.oAClient.obj) except Exception: pass return CommandResult.Failed() if len(members) > 3: message.ReplyText("There can only be you, me, and the other bot") return CommandResult.Failed() sender.rObj = chatroom message.ReplyText("This room has been registered as %s's RObj" % sender.name) return CommandResult.Done()
def DeepArtBuiltin(message, style, images): if not style.isdigit(): message.ReplyText("Invalid style (1)") return CommandResult.Failed() r = post( 'http://turbo.deepart.io/api/post/', data={ 'style': style, 'return_url': 'http://my.return/' }, files={'input_image': ('file.jpg', images[0].bytes, 'image/jpeg')}) img = r.text if len(img) > 100: message.ReplyText("Invalid style (2)") return CommandResult.Failed() path = ("/media/output/%s.jpg" % img) link = "https://turbo.deepart.io" + path message.ReplyText("[DeepArt] Please wait up to 3 minutes.\n" + link) WaitOK("turbo.deepart.io", path) img = Image(url=link) return CommandResult.Done(images=[img])
def Send(self): if self.nums: s = "Round %d\n%s" % (self.round, '\n'.join( ("%s : %d (%d)" % (player.name, player.score, player.pendingScore)) for player in self.players)) self.SendText( "Round%d\n%s\n%d seconds left.\nType '/242 done' if you figured it out\nPlayers who 'figured it out':%d\n%s\nPlayers who 'haven't figured it out':%d\n%s" % (self.round, " ".join("%g" % x for x in self.nums), round(self.end - time()), len(self.winners), '\n'.join( ("%s : %d (%d)" % (x.name, x.score, x.pendingScore)) for x in self.winners), len(self.losers), '\n'.join( ("%s : %d" % (x.name, x.score)) for x in self.losers))) buts = Buttons("Have you figured it out?") buts.AddButton("Yes", "/242 done", "\nIf so, type '/242 done'") self.SendButtons(buts) else: buts = Buttons( "TwentyFour2 is already running, but not started yet.") buts.AddButton("Force Start", "/242 forcestart", "\nTo start it, type '/242 forcestart'") self.SendButtons(buts) return CommandResult.Done()
def _1Activate(message, name, fr, fs): if fr: if fs: rUrl = fr[0] rDesc = fr[1] sUrl = fs[0] sDesc = fs[1] if rUrl == sUrl and rDesc == sDesc: return RegisterMeme(message, name=name, images=[Image(url=rUrl)], desc=rDesc, mode=0, options=options, insert=False) else: rRes = RegisterMeme(message, name=name, images=[Image(url=rUrl)], desc=rDesc, mode=1, options=options, insert=False) sRes = RegisterMeme(message, name=name, images=[Image(url=sUrl)], desc=sDesc, mode=2, options=options, insert=False) if rRes.images: if sRes.images: return CommandResult.Done(images=rRes.images + sRes.images) return rRes elif sRes.images: return sRes else: rTexts = rRes.texts sTexts = sRes.texts if rTexts: if sTexts: return CommandResult.Done(texts=rTexts + sTexts) return rRes elif sTexts: return sRes return CommandResult.Done(texts=["Unknown Error"]) else: return RegisterMeme(message, name=name, images=[Image(url=fr[0])], desc=fr[1], mode=1, options=options, insert=False) elif fs: return RegisterMeme(message, name=name, images=[Image(url=fs[0])], desc=fs[1], mode=2, options=options, insert=False) return CommandResult.Done()
def Explain(self, obj, text): sender = obj with self.lock: if not self.phase == RoomPhase.explain: return CommandResult.Failed() if obj not in self.playersByObj: return CommandResult.Failed() explainer = self.playersByObj[obj] if explainer != self.explainer: return CommandResult.Failed() if not self.nums: return CommandResult.Failed() text = text.strip() if not IsValid(text): return CommandResult.Failed() mExRx = Room.exRx.match(text) if not mExRx: return CommandResult.Failed() nums = None try: nums = [ float(mExRx.group(2)), float(mExRx.group(6)), float(mExRx.group(10)), float(mExRx.group(14)) ] except Exception as e: self.SendText("Error. Invalid numbers.\n%s" % (s, e)) return CommandResult.Done() try: for i in range(0, 4): x = nums[i] if x < self.bot or x > self.top: raise Exception( "Only integers ranging from %d-%d are allowed. %g is not in range" % (self.bot, self.top, x)) y = int(x) if x != y: raise Exception( "Only integers ranging from %d-%d are allowed. %g is not an integer" % (self.bot, self.top, x)) nums[i] = y except Exception as e: self.SendText("Error. Invalid numbers.\n%s" % (s, e)) return CommandResult.Done() nums.sort() if nums != self.nums: self.SendText("Error. Invalid numbers.\n%s != %s" % (nums, self.nums)) return CommandResult.Done() s = '' for i in range(1, 16): c = mExRx.group(i) if c: s = s + c try: name = '' if explainer.name: name = ", %s" % explainer.name ret = float(eval(text)) if ret == 24: rep = "Correct%s.\n%s == 24" self.SendText(rep % (name, s)) self.explained = True with self.cond: self.cond.notifyAll() else: rep = "Wrong%s.\n%s == %g" self.SendText(rep % (name, s, ret)) except Exception as e: self.SendText( "Error. '%s' may not be a valid math expression.\n%s" % (s, e)) return CommandResult.Done()
def LunaPic(message, options, text='', images=[]): link = images[0].imgurUrl splitArgs = text.split(' ') if splitArgs[0] == 'random': if len(splitArgs) < 1 or isEmpty(splitArgs[1]) or not splitArgs[1].isdigit(): iterations = 1 else: iterations = int(splitArgs[1]) if iterations < 1: iterations = 1 if iterations > 20: iterations = 20 #l = list(lpRandoms) splitArgs = [] for i in range(0, iterations): #splitArgs.append(l.pop(randint(0, len(l) - 1))) splitArgs.append(lpRandoms[randint(0,maxLpRandomIndex)]) print(str(splitArgs)) s = Session() r0 = s.get("http://lunapic.com/editor/?action=" + splitArgs[0] + "&url=" + link) if r0.status_code != 200: message.ReplyText("Error LP 1. LunaPic is probably down. Please try again later.") return lp0m = lprx0.match(r0.url) if lp0m is None: #print(r0.text) message.ReplyText("Error LP 2. LunaPic is probably down. Please try again later.") return lpurl = 'http://' + lp0m.group(1) + '/editor/' for arg0 in splitArgs: arg1 = arg0.split(':') arg = arg1[0] if arg not in lpActions: continue arg2 = None if len(arg1) > 1: arg2 = arg1[1] info = {'action':arg, 'url':link} if arg == 'tint' or arg == 'groovy-color': if arg2 is None: arg2 = lpColors[randint(0, maxLpColorIndex)] info['color'] = arg2 if arg == 'transitions': if arg2 is None: arg2 = lpTransitions[randint(0, maxLpTransitionIndex)] info['type'] = arg2 if arg == 'scan': if arg2 is None: arg2 = 1 info['hoz'] = arg2 r1 = s.post(lpurl, data=info) if r1.status_code != 200: message.ReplyText("Error LP 3. LunaPic is probably down\n" + "lpurl='" + lpurl + "'\ninfo='" + str(info) + "'") return CommandResult.Failed() r2a = s.get(lpurl + "?action=imgur") if r2a.status_code != 200: message.ReplyText("Error LP 4. LunaPic is probably down\n" + "lpurl='" + lpurl + "'\ninfo='" + str(info) + "'") return CommandResult.Failed() mLpimgurRx = lpimgurRx.match(r2a.text) if mLpimgurRx is None: message.ReplyText("Error LP 5. LunaPic is probably down or you submitted invalid action\n" + "lpurl='" + lpurl + "'\ninfo='" + str(info) + "'") return CommandResult.Failed() link = mLpimgurRx.group(1).replace("http:", "https:") img = Image(url=link) return CommandResult.Done(images=[img])
def NewMeme(message, options, name, desc=None, mode=None, admin=False, images=None, params=None): if mode is None: if admin: mode = 10 else: mode = 0 if 'r' in options: mode = 1 elif 's' in options: mode = 2 if params: params['mode'] = mode if not IsEmpty(images): return RegisterMeme(message, options, name, desc, mode, images, params) if 'f' not in options: cur = message.client.GetCursor() if mode == 10: cur.Execute('SELECT TRUE FROM CustomMemes WHERE name=%s', (name, )) if cur.rowCount > 0: message.ReplyText( "[Command(Meme)] Global template named '%s' already exists. If you want to replace, please also provide the 'f' (force) option" % name) return CommandResult.Done() roomMemeExists = False if mode == 0 or mode == 1: cur.Execute( 'SELECT TRUE FROM RoomCustomMemes WHERE name=%s AND rId=%s', (name, message.chatroom._2id)) if cur.rowCount > 0: if mode == 0: roomMemeExists = True else: message.ReplyText( "[Command(Meme)] Room template named '%s' already exists. If you want to replace, please also provide the 'f' (force) option" % name) return CommandResult.Done() userMemeExists = 0 if not message.sender: userMemeExists = 2 elif mode == 0 or mode == 2: cur.Execute( 'SELECT TRUE FROM UserCustomMemes WHERE name=%s AND uId=%s', (name, message.sender._2id)) if cur.rowCount > 0: if mode == 0: userMemeExists = 1 else: message.ReplyText( "[Command(Meme)] User template named '%s' already exists. If you want to replace, please also provide the 'f' (force) option" % name) return CommandResult.Done() if mode == 0: if roomMemeExists: if userMemeExists == 2: message.ReplyText( "[Command(Meme)] Room template named '%s' already exists. We can't identify you so user template is also not possible. If you want to replace, please also provide the 'f' (force) option" % name) return CommandResult.Done() elif userMemeExists == 1: message.ReplyText( "[Command(Meme)] Room template and user template named '%s' already exists. If you want to replace, please also provide the 'f' (force) option" % name) return CommandResult.Done() elif userMemeExists == 0: message.ReplyText( "[Command(Meme)] Room template named '%s' already exists. This way, only user template will be registered. If you want to replace the room template too, please also provide the 'f' (force) option" % name) mode = 2 else: if userMemeExists == 2: message.ReplyText( "[Command(Meme)] We can't identify you so user template is not possible. This way, only user template will be registered." ) mode = 1 elif userMemeExists == 1: message.ReplyText( "[Command(Meme)] User template named '%s' already exists. This way, only the room template will be registered. If you want to replace, please also provide the 'f' (force) option" % name) mode = 1 if params: params['mode'] = mode return CommandResult.ExpectImage()
def DeepStyle(message, options, images=[]): print("Getting session") s = Session() s.auth = (dsEmail, dsPw) s.headers.update({'User-Agent' : str(UserAgent().chrome)}) print("Getting token") rToken = s.get(dsLoginUrl) if rToken.status_code != 200: message.ReplyText("Error DS 1") return CommandResult.Failed() mToken = dsTokenRx.match(rToken.text) token = mToken.group(1) info = {"_token":token, "email":dsEmail, "password":dsPw, "remember":"true"} print("Logging in") rLogin = s.post(dsLoginUrl, data=info) if rLogin.status_code != 200: message.ReplyText("Error DS 2") return CommandResult.Failed() TryChangeToken(rLogin.text, info) rDeepStyle = s.get(dsUrl, data=info) if rDeepStyle.status_code != 200: message.ReplyText("Error DS 3") return CommandResult.Failed() info = {"_token":info["_token"]} TryChangeToken(rDeepStyle.text, info) print("Getting images") style = images[0].bytes img = images[1].bytes print("Requesting deepstyle") info["style"] = "custom" info["dreamType"]="deep-style" info["resolution"]="normal" info["optimizer"]="alpha" info["iterationsDepth"] ="normal" info["preserveOriginalColors"]="no" info["access"] = "public" info["styleScale"] = "1" info["styleWeight"] = "5" rUploadImg = s.post(dsUploadUrl, data=info, files={'image':img, 'styleImage':style}) if rUploadImg.status_code != 200: message.ReplyText("Error DS 4\n" + rUploadImg.text) return CommandResult.Failed() mDsLink = dsLinkRx.match(rUploadImg.text) if mDsLink is None: message.ReplyText("Error DS 5 : '" + dsErrorRx.match(rUploadImg.text).group(1).replace('"', '"') + "'") return CommandResult.Failed() while mDsLink is None: time.sleep(300) rUploadImg = s.post(dsUploadUrl, data=info, files={'image':img, 'styleImage':style}) if rUploadImg.status_code != 200: message.ReplyText("Error DS 6") return CommandResult.Failed() mDsLink = dsLinkRx.match(rUploadImg.text) dsLink = mDsLink.group(1) message.ReplyText("[DeepStyle] Please wait up to 5 minutes\n" + dsLink) mDsLinkParse = dsLinkParseRx.match(dsLink) host = mDsLinkParse.group(1) path = mDsLinkParse.group(2) WaitOK(host, path) img = Image(url=dsLink) return CommandResult.Done(images=[img])
def Activate(message, options, name, admin=False, activate=True): mode = 0 if admin: mode = 10 elif 'r' in options: mode = 1 elif 's' in options: mode = 2 s = 'a' if not activate: s = 'dea' sT = 'A' if not activate: sT = 'Dea' sDate = 'NULL' if not activate: sDate = 'NOW()' if not message.sender: if mode == 0: message.ReplyText( "[Command(Meme)] Unfortunately we can't identify you so only room meme template named '%s' will be %sctivated if exists" % (name, s)) mode = 1 elif mode == 2: message.ReplyText( "[Command(Meme)] Unfortunately we can't identify you so your request can't be fulfilled." ) return CommandResult.Done() cur = message.client.GetCursor() f = None if mode == 10: cur.Execute( "UPDATE CustomMemes SET deactivationDatetime=" + sDate + " WHERE name=%s RETURNING imageUrl, description", (name, )) if cur.rowCount == 0: message.ReplyText( "[Command(Meme)] %sctivating global meme template failed, template named '%s' not found" % (sT, name)) return CommandResult.Done() f = cur.FetchOne() if activate: return RegisterMeme(message, name=name, images=[Image(url=f[0])], desc=f[1], mode=mode, options=options, insert=False) fr = None if mode == 0 or mode == 1: rId = message.chatroom._2id cur.Execute( "UPDATE RoomCustomMemes SET deactivationDatetime=" + sDate + " WHERE rId=%s AND name=%s RETURNING imageUrl, description", ( rId, name, )) if cur.rowCount == 0: message.ReplyText( "[Command(Meme)] %sctivating room meme template failed, template named '%s' not found" % (sT, name)) if mode == 1: return CommandResult.Done() else: fr = cur.FetchOne() if mode == 1: cur.Commit() if activate: return RegisterMeme(message, name=name, images=[Image(url=fr[0])], desc=fr[1], mode=1, options=options, insert=False) fs = None if mode == 0 or mode == 2: uId = message.chatroom._2id cur.Execute( "UPDATE UserCustomMemes SET deactivationDatetime=" + sDate + " WHERE uId=%s AND name=%s RETURNING imageUrl, description", ( uId, name, )) if cur.rowCount == 0: message.ReplyText( "[Command(Meme)] %sctivating user meme template failed, template named '%s' not found" % (sT, name)) if mode == 2: return CommandResult.Done() else: fs = cur.FetchOne() if mode == 2: cur.Commit() if activate: return RegisterMeme(message, name=name, images=[Image(url=fs[0])], desc=fs[1], mode=2, options=options, insert=False) cur.Commit() if activate: return _1Activate(message, name, fr, fs) return _1Deactivate(message, name, f, fr, fs)
def Meme(message, options='', text='', name=None, top=' ', bot=' ', font='impact', img=None, desc=None, images=None, admin=False, mode=None, params=None, activate=None, deactivate=None, new=None): if params is None: params = {} if text == 'templates': return SendTemplateList(message.chatroom, message.sender) a, b, c = text.partition(' ') if not IsEmpty(c): x = None if a == 'new': x = 'n' elif a == 'activate': x = 'a' elif a == 'deactivate': x = 'd' if x: options = options + x params['options'] = options text = c.strip() if activate: name = activate options = options + 'a' params['options'] = options if deactivate: name = deactivate options = options + 'd' params['options'] = options if new: name = new options = options + 'n' params['options'] = options if 'n' in options or 'a' in options or 'd' in options: if IsEmpty(name): name = text if IsEmpty(name): message.ReplyText("[Command(Meme):New] Name can't be empty") return CommandResult.Done() if 'n' in options: if name in invalidNames: message.ReplyText("[Command(Meme):New] Name can't be '%s'" % name) return CommandResult.Done() return NewMeme(message, options, name, desc, mode, admin, images, params) if 'a' in options: return Activate(message, options, name, admin=admin) return Activate(message, options, name, admin=admin, activate=False) if name is None: if IsEmpty(text) or not IsEmpty2(top) or not IsEmpty2( bot) or not IsEmpty(options): name = 'random' else: name = text.split(' ')[0] if IsEmpty(name): chatroom.SendText("[Command(Meme)] Name can't be empty.") return CommandResult.Done() if name == 'custom': if IsEmpty2(top) and IsEmpty2(bot): message.ReplyText( "[Command(Meme)] Just send the image yourself wtf") return CommandResult.Done() if IsEmpty(img): if images is None or len(images) == 0: return CommandResult.ExpectImage() img = images[0].imgurUrl if IsEmpty(img): message.ReplyText("Failed to reupload image.") return CommandResult.ExpectImage() return Send(message.chatroom, message.sender, name, top, bot, font, img)
def DeepFry(message, options, images=[], quality=90, iterations=3, pixel=0.95, iterations2=3, tint="rgb(255,160,100)"): img = images[0].bytes imgIn = BytesIO(img) baseQuality = quality scale = pixel secondIter = iterations2 tintColor = tint quality = baseQuality img = PILImage.open(imgIn) for i in range(0, iterations): img = ImageEnhance.Contrast(img).enhance(2) img = ImageEnhance.Sharpness(img).enhance(2) img = ImageEnhance.Contrast(img).enhance(2) img = img.filter(ImageFilter.SHARPEN) img = ImageEnhance.Contrast(img).enhance(2) img = img.filter(ImageFilter.EDGE_ENHANCE) img = ImageEnhance.Contrast(img).enhance(2) #img = img.filter(ImageFilter.EDGE_ENHANCE_MORE) imgOut = BytesIO() img.save(imgOut, "JPEG", quality=quality) quality = int(quality * baseQuality / 100) imgOut.seek(0) img = PILImage.open(imgOut) quality = baseQuality if scale < 1: ori = (img.width, img.height) img = img.resize((int(img.width * scale), int(img.height * scale))) img = Tint(img, tintColor) img = ImageEnhance.Sharpness(img).enhance(2) img = img.filter(ImageFilter.SHARPEN) img = img.filter(ImageFilter.EDGE_ENHANCE) img = ImageEnhance.Sharpness(img).enhance(2) img = img.filter(ImageFilter.SHARPEN) img = ImageEnhance.Contrast(img).enhance(2) img = ImageOps.autocontrast(img) if scale < 1: img = img.resize(ori, PILImage.NEAREST) imgOut = BytesIO() img.save(imgOut, "JPEG", quality=quality) imgOut.seek(0) img = PILImage.open(imgOut) for i in range(0, secondIter): imgOut = BytesIO() img.save(imgOut, "JPEG", quality=quality) quality = int(quality * baseQuality / 100) imgOut.seek(0) img = PILImage.open(imgOut) imgOut = BytesIO() img.save(imgOut, "JPEG", quality=quality) imgOut.seek(0) img = imgOut.read() img = Image(bytes=img) return CommandResult.Done(images=[img])