From 1c6f9119e98bf95849ac2bf9783e8348bc89948e Mon Sep 17 00:00:00 2001 From: Nick80835 Date: Fri, 19 Jun 2020 14:40:41 -0400 Subject: [PATCH] reduce stupid code --- ubot/micro_bot.py | 6 +++++- ubot/modules/4chan.py | 4 +--- ubot/modules/catdog.py | 4 +--- ubot/modules/danbooru.py | 4 +--- ubot/modules/deepfry.py | 4 +--- ubot/modules/evaluation.py | 4 +--- ubot/modules/gelbooru.py | 4 +--- ubot/modules/memes.py | 4 +--- ubot/modules/nekos.py | 4 +--- ubot/modules/reddit.py | 4 +--- ubot/modules/sankaku.py | 4 +--- ubot/modules/scrapers.py | 3 +-- ubot/modules/sticklet.py | 4 +--- ubot/modules/sudo.py | 4 +--- ubot/modules/system.py | 4 +--- ubot/modules/urbandict.py | 4 +--- 16 files changed, 20 insertions(+), 45 deletions(-) diff --git a/ubot/micro_bot.py b/ubot/micro_bot.py index 9a6d995..e4f9f8d 100644 --- a/ubot/micro_bot.py +++ b/ubot/micro_bot.py @@ -27,6 +27,8 @@ class MicroBot(): self.start_logger() self.start_client() self.start_loader() + + def run_until_done(self): self.loader.load_all_modules() self.logger.info("Client successfully started.") self.client.run_until_disconnected() @@ -81,8 +83,10 @@ class MicroBot(): micro_bot = MicroBot() +micro_bot.start_microbot() +ldr = micro_bot.loader try: - micro_bot.start_microbot() + micro_bot.run_until_done() except: micro_bot.client.loop.run_until_complete(micro_bot.stop_client()) diff --git a/ubot/modules/4chan.py b/ubot/modules/4chan.py index f4d14b7..584d05c 100644 --- a/ubot/modules/4chan.py +++ b/ubot/modules/4chan.py @@ -2,9 +2,7 @@ from random import choice, shuffle -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr BOARD_URL = "https://a.4cdn.org/{0}/threads.json" POST_URL = "https://a.4cdn.org/{0}/thread/{1}.json" diff --git a/ubot/modules/catdog.py b/ubot/modules/catdog.py index 7fe6250..f1006df 100644 --- a/ubot/modules/catdog.py +++ b/ubot/modules/catdog.py @@ -1,8 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr CAT_URL = 'http://api.thecatapi.com/v1/images/search' DOG_URL = 'http://api.thedogapi.com/v1/images/search' diff --git a/ubot/modules/danbooru.py b/ubot/modules/danbooru.py index b404008..7eab744 100644 --- a/ubot/modules/danbooru.py +++ b/ubot/modules/danbooru.py @@ -2,9 +2,7 @@ from time import time_ns -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr DAN_URL = "http://danbooru.donmai.us/posts.json" DAN_SAUCE_URL = "https://danbooru.donmai.us/posts/" diff --git a/ubot/modules/deepfry.py b/ubot/modules/deepfry.py index d88dc3d..e58fffc 100644 --- a/ubot/modules/deepfry.py +++ b/ubot/modules/deepfry.py @@ -31,9 +31,7 @@ from random import randint, uniform from PIL import Image, ImageEnhance, ImageOps from telethon.tl.types import DocumentAttributeFilename -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr @ldr.add("deepfry(f|)", userlocking=True) diff --git a/ubot/modules/evaluation.py b/ubot/modules/evaluation.py index ce18b78..7967544 100644 --- a/ubot/modules/evaluation.py +++ b/ubot/modules/evaluation.py @@ -6,9 +6,7 @@ import io from PIL import Image, ImageOps from speedtest import Speedtest -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr @ldr.add("speed", owner=True, hide_help=True) diff --git a/ubot/modules/gelbooru.py b/ubot/modules/gelbooru.py index 09966e7..33b6b4c 100644 --- a/ubot/modules/gelbooru.py +++ b/ubot/modules/gelbooru.py @@ -3,9 +3,7 @@ from random import choice from time import time_ns -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr GEL_URL = "https://gelbooru.com/index.php" GEL_SAUCE_URL = "https://gelbooru.com/index.php?page=post&s=view&id=" diff --git a/ubot/modules/memes.py b/ubot/modules/memes.py index c69fe70..9af2caf 100644 --- a/ubot/modules/memes.py +++ b/ubot/modules/memes.py @@ -3,9 +3,7 @@ from asyncio import sleep from random import choice, randint -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr emoji = list("πŸ˜‚πŸ˜πŸ€ͺ🀩😀πŸ₯΅πŸ€―πŸ₯ΆπŸ˜±πŸ€”πŸ˜©πŸ™„πŸ’€πŸ‘»πŸ€‘πŸ˜ΉπŸ‘€πŸ‘πŸ‘ŒπŸ’¦πŸ”₯πŸŒšπŸŒπŸŒžπŸ”«πŸ’―") b_emoji = "πŸ…±οΈ" diff --git a/ubot/modules/nekos.py b/ubot/modules/nekos.py index 7d908ee..731e4f7 100644 --- a/ubot/modules/nekos.py +++ b/ubot/modules/nekos.py @@ -4,9 +4,7 @@ import io from PIL import Image -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr NEKO_URL = "https://nekos.life/api/v2/img/" NEKO_TYPES = ['neko', 'lewd', 'smug', 'tits', 'trap', 'anal', 'cuddle', 'hug', 'goose', 'waifu', 'gasm', 'slap', 'spank', 'pat', 'feet', 'woof', 'baka'] diff --git a/ubot/modules/reddit.py b/ubot/modules/reddit.py index cccba67..35918d5 100644 --- a/ubot/modules/reddit.py +++ b/ubot/modules/reddit.py @@ -6,9 +6,7 @@ from random import choice, shuffle import praw from prawcore import exceptions as redex -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr REDDIT = praw.Reddit(client_id='-fmzwojFG6JkGg', client_secret=None, diff --git a/ubot/modules/sankaku.py b/ubot/modules/sankaku.py index 6c9ee98..afad881 100644 --- a/ubot/modules/sankaku.py +++ b/ubot/modules/sankaku.py @@ -2,9 +2,7 @@ from time import time_ns -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr SAN_URL = "https://capi-v2.sankakucomplex.com/posts" SAN_SAUCE_URL = "https://beta.sankakucomplex.com/post/show/" diff --git a/ubot/modules/scrapers.py b/ubot/modules/scrapers.py index 6911ecf..357b5d1 100644 --- a/ubot/modules/scrapers.py +++ b/ubot/modules/scrapers.py @@ -9,9 +9,8 @@ from gtts import gTTS from howdoi import howdoi from PIL import Image -from ubot.micro_bot import micro_bot +from ubot.micro_bot import ldr -ldr = micro_bot.loader os.environ["HOWDOI_SEARCH_ENGINE"] = "bing" diff --git a/ubot/modules/sticklet.py b/ubot/modules/sticklet.py index e5d9df3..5c91198 100644 --- a/ubot/modules/sticklet.py +++ b/ubot/modules/sticklet.py @@ -4,9 +4,7 @@ import io from PIL import Image, ImageColor -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr @ldr.add("color") diff --git a/ubot/modules/sudo.py b/ubot/modules/sudo.py index 1cce135..a84642a 100644 --- a/ubot/modules/sudo.py +++ b/ubot/modules/sudo.py @@ -5,9 +5,7 @@ from platform import python_version from telethon import version -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr, micro_bot @ldr.add("reload", sudo=True, hide_help=True) diff --git a/ubot/modules/system.py b/ubot/modules/system.py index 34fdd69..819a197 100644 --- a/ubot/modules/system.py +++ b/ubot/modules/system.py @@ -4,9 +4,7 @@ from time import time_ns from telethon import version -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr @ldr.add("del") diff --git a/ubot/modules/urbandict.py b/ubot/modules/urbandict.py index 037c402..2018626 100644 --- a/ubot/modules/urbandict.py +++ b/ubot/modules/urbandict.py @@ -2,9 +2,7 @@ import io -from ubot.micro_bot import micro_bot - -ldr = micro_bot.loader +from ubot.micro_bot import ldr UD_QUERY_URL = 'http://api.urbandictionary.com/v0/define' UD_RANDOM_URL = 'http://api.urbandictionary.com/v0/random'