-
Notifications
You must be signed in to change notification settings - Fork 17
Sourcery Starbot ⭐ refactored Aioxas/ax-cogs #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ async def set(self, ctx): | |
| else: | ||
| self.servers[server.id]["status"] = not self.servers[server.id]["status"] | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| # for a toggle, settings should save here in case bot fails to send message | ||
| if self.servers[server.id]["status"]: | ||
|
|
@@ -69,7 +69,7 @@ async def add(self, ctx, name, url): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| if not url.endswith((".gif", ".gifv", ".png")): | ||
| await self.bot.say("Links ending in .gif, .png, and .gifv are the only ones accepted." | ||
|
|
@@ -108,7 +108,7 @@ async def remove(self, ctx, name): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| if name in self.servers[server.id]["emotes"]: | ||
| os.remove(self.emote+self.servers[server.id]["emotes"][name]) | ||
|
|
@@ -136,7 +136,7 @@ async def edit(self, ctx, name, newname): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| if newname in self.servers[server.id]["emotes"]: | ||
| await self.bot.say("This keyword already exists, please use another keyword.") | ||
|
|
@@ -172,7 +172,7 @@ async def list(self, ctx, style): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| istyles = sorted(self.servers[server.id]["emotes"]) | ||
| if not istyles: | ||
|
|
@@ -189,7 +189,7 @@ async def list(self, ctx, style): | |
| istyle = [] | ||
| for i in range(len(istyles)): | ||
| ist = re.findall("\\b"+style+"\\w+", istyles[i]) | ||
| istyle = istyle + ist | ||
| istyle += ist | ||
| style = 10 | ||
| else: | ||
| await self.bot.say("Your list style is not correct, please use one" | ||
|
|
@@ -202,16 +202,13 @@ async def list(self, ctx, style): | |
| if style <= count: | ||
| y = s.join(istyle[:style]) | ||
| await self.bot.say("List of available emotes:\n{}".format(y)) | ||
| if style > len(istyle): | ||
| return | ||
| style += count | ||
| elif style > count: | ||
| else: | ||
| style2 = style - count | ||
| y = s.join(istyle[style2:style]) | ||
| await self.bot.say("Continuation:\n{}".format(y)) | ||
| if style > len(istyle): | ||
| return | ||
| style += count | ||
| if style > len(istyle): | ||
| return | ||
| style += count | ||
| await self.bot.say("Do you want to continue seeing the list? Yes/No") | ||
| answer = await self.bot.wait_for_message(timeout=15, | ||
| author=ctx.message.author) | ||
|
|
@@ -242,20 +239,18 @@ async def compare(self, ctx, style, alls: str=None): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
| dataIO.save_json(self.data_path, self.servers) | ||
| if style not in styleset: | ||
| return | ||
| msg = "Keywords deleted due to missing files in the emotes list:\n" | ||
| c = list() | ||
| for entry in os.scandir(self.emote): | ||
| c.append(entry.name) | ||
| c = [entry.name for entry in os.scandir(self.emote)] | ||
| if style == styleset[0]: | ||
| msg = "Keywords deleted due to missing files in the emotes list:\n" | ||
| if alls == "all": | ||
| servers = sorted(self.servers) | ||
| servers.remove("emote") | ||
| for servs in servers: | ||
| missing = list() | ||
| missing = [] | ||
|
Comment on lines
-245
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| istyles = sorted(self.servers[servs]["emotes"]) | ||
| for n in istyles: | ||
| cat = "|".join(c) | ||
|
|
@@ -282,16 +277,13 @@ async def compare(self, ctx, style, alls: str=None): | |
| if style <= 10: | ||
| y = s.join(missing[:style]) | ||
| await self.bot.say(msg + y) | ||
| if style >= len(missing): | ||
| break | ||
| style += 10 | ||
| elif style > 10: | ||
| else: | ||
| style2 = style - 10 | ||
| y = s.join(missing[style2:style]) | ||
| await self.bot.say("Continuation:\n{}".format(y)) | ||
| if style >= len(missing): | ||
| break | ||
| style += 10 | ||
| if style >= len(missing): | ||
| break | ||
| style += 10 | ||
| await self.bot.say("Do you want to continue seeing the list? Yes/No") | ||
| answer = await self.bot.wait_for_message(timeout=15, | ||
| author=ctx.message.author) | ||
|
|
@@ -325,16 +317,13 @@ async def compare(self, ctx, style, alls: str=None): | |
| if style <= 10: | ||
| y = s.join(missing[:style]) | ||
| await self.bot.say(msg + y) | ||
| if style >= len(missing): | ||
| return | ||
| style += 10 | ||
| elif style > 10: | ||
| else: | ||
| style2 = style - 10 | ||
| y = s.join(missing[style2:style]) | ||
| await self.bot.say("Continuation:\n{}".format(y)) | ||
| if style >= len(missing): | ||
| return | ||
| style += 10 | ||
| if style >= len(missing): | ||
| return | ||
| style += 10 | ||
| await self.bot.say("Do you want to continue seeing the list? Yes/No") | ||
| answer = await self.bot.wait_for_message(timeout=15, | ||
| author=ctx.message.author) | ||
|
|
@@ -416,13 +405,13 @@ async def check_emotes(self, message): | |
| # default off | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
| dataIO.save_json(self.data_path, self.servers) | ||
| # emotes is off, so ignore | ||
| if "status" not in self.servers[server.id]: | ||
| self.servers[server.id] = dict({"status": False}) | ||
| if "emotes" not in self.servers[server.id]: | ||
| self.servers[server.id]["emotes"] = dict() | ||
| self.servers[server.id]["emotes"] = {} | ||
|
Comment on lines
-419
to
+414
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json(self.data_path, self.servers) | ||
| if not self.servers[server.id]["status"]: | ||
| return | ||
|
|
@@ -478,12 +467,11 @@ def check_folders(): | |
|
|
||
|
|
||
| def check_files(): | ||
| # create server.json if not there | ||
| # put in default values | ||
| default = {} | ||
| default['emote'] = 'data/emote/images/' | ||
| if not os.path.isfile('data/emote/servers.json'): | ||
| print('Creating default emote servers.json...') | ||
| # create server.json if not there | ||
| # put in default values | ||
| default = {'emote': 'data/emote/images/'} | ||
|
Comment on lines
-481
to
+474
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json('data/emote/servers.json', default) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ async def _bash(self, ctx, num: int=1): | |
| if num > 5: | ||
| num = 5 | ||
| await self.bot.reply("Heck naw brah. 5 is max. Any more and you get killed.") | ||
| for i in range(num): | ||
| for _ in range(num): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| async with aiohttp.request("GET", 'http://bash.org/?random') as resp: | ||
| test = str(await resp.text()) | ||
| subs = re.findall(regex[0], test) | ||
|
|
@@ -49,7 +49,7 @@ async def _quotes(self, ctx, *, author: str): | |
| async with aiohttp.request("GET", url) as resp: | ||
| test = str(await resp.text()) | ||
| quote_find = list(set(re.findall(regex, test))) | ||
| for i in range(number): | ||
| for _ in range(number): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| random_quote = choice(quote_find) | ||
| quote_find.remove(random_quote) | ||
| while random_quote == title: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,14 +138,14 @@ def getchinese_signs(self, year): | |
| @commands.cooldown(10, 60, commands.BucketType.user) | ||
| async def _cookie(self): | ||
| """Retrieves a random fortune cookie fortune.""" | ||
| regex = ["class=\"cookie-link\">([^`]*?)<\/a>", "<p>([^`]*?)<\/p>", | ||
| "(?:\\\\['])", "<strong>([^`]*?)<\/strong>", | ||
| "<\/strong><\/a>([^`]*?)<br>", | ||
| "3\)<\/strong><\/a>([^`]*?)<\/div>"] | ||
| url = "http://www.fortunecookiemessage.com" | ||
| await self.file_check() | ||
| async with self.session.get(url, headers={"encoding": "utf-8"}) as resp: | ||
| test = str(await resp.text()) | ||
| regex = ["class=\"cookie-link\">([^`]*?)<\/a>", "<p>([^`]*?)<\/p>", | ||
| "(?:\\\\['])", "<strong>([^`]*?)<\/strong>", | ||
| "<\/strong><\/a>([^`]*?)<br>", | ||
| "3\)<\/strong><\/a>([^`]*?)<\/div>"] | ||
|
Comment on lines
-141
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| fortune = re.findall(regex[0], test) | ||
| fortest = re.match("<p>", fortune[0]) | ||
| if fortest is not None: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ async def cat(self, ctx): | |
| the_cat = [Image.open(self.path + "butt.png")] | ||
| trunk = Image.open(self.path + "trunk.png") | ||
| head = Image.open(self.path + "head.png") | ||
| for i in range(len_cat-1): | ||
| for _ in range(len_cat-1): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| the_cat.append(trunk) | ||
| the_cat.append(head) | ||
| widths, heights = zip(*(i.size for i in the_cat)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,7 @@ async def remove(self, ctx, name: str, char: str=None): | |
| elif char in self.db[server.id][name]: | ||
| del self.db[server.id][name][char] | ||
| dataIO.save_json("data/loot/servers.json", self.db) | ||
| await self.bot.say("{} has been removed".format(char if char else name)) | ||
| await self.bot.say("{} has been removed".format(char or name)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def check_folders(): | ||
|
|
@@ -107,11 +107,11 @@ def check_folders(): | |
|
|
||
|
|
||
| def check_files(): | ||
| # create servers.json if not there | ||
| # put in default values | ||
| default = {} | ||
| if not os.path.isfile('data/loot/servers.json'): | ||
| print('Creating default loot servers.json...') | ||
| # create servers.json if not there | ||
| # put in default values | ||
| default = {} | ||
|
Comment on lines
-110
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json('data/loot/servers.json', default) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,15 +40,12 @@ async def add(self, ctx, name: str, content: str, multi: int=None): | |
| content = content.split(", ") | ||
| elif "," in content: | ||
| content = content.split(",") | ||
| if multi < 0: | ||
| neg = True | ||
| multi = abs(multi) | ||
| if multi and type(content) is not list: | ||
| if multi < 0: | ||
| neg = True | ||
| multi = abs(multi) | ||
| content = [content.lower()] * multi | ||
| else: | ||
| if multi < 0: | ||
| neg = True | ||
| multi = abs(multi) | ||
|
Comment on lines
+43
to
-51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| content = content * multi | ||
| print(content) | ||
| for x in content: | ||
|
|
@@ -140,7 +137,7 @@ async def append(self, ctx, name: str, items: str): | |
| Names are fixed when they are added.""" | ||
| server = ctx.message.server | ||
| items = items.split(", ") | ||
| itemis = dict() | ||
| itemis = {} | ||
|
Comment on lines
-143
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for item in items: | ||
| item, value = item.split(" ") | ||
| item = item.replace("_", " ").lower() | ||
|
|
@@ -171,7 +168,7 @@ async def remove(self, ctx, name: str, items: str): | |
| Names are fixed when they are added.""" | ||
| server = ctx.message.server | ||
| items = items.split(", ") | ||
| itemis = dict() | ||
| itemis = {} | ||
|
Comment on lines
-174
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for item in items: | ||
| item, value = item.split(" ") | ||
| item = item.replace("_", " ").lower() | ||
|
|
@@ -293,11 +290,11 @@ def check_folders(): | |
|
|
||
|
|
||
| def check_files(): | ||
| # create servers.json if not there | ||
| # put in default values | ||
| default = {} | ||
| if not os.path.isfile('data/lootbox/servers.json'): | ||
| print('Creating default lootbox servers.json...') | ||
| # create servers.json if not there | ||
| # put in default values | ||
| default = {} | ||
|
Comment on lines
-296
to
+297
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dataIO.save_json('data/lootbox/servers.json', default) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
AdvancedGoogle.imagesrefactored with the following changes:remove-redundant-if)assign-if-exp)