mirror of
https://github.com/Nick80835/microbot
synced 2025-09-04 00:15:34 +00:00
allow simplifying command registry to just a string arg for the pattern
This commit is contained in:
@@ -42,9 +42,11 @@ class Loader():
|
||||
|
||||
return errors or None
|
||||
|
||||
def add(self, **args):
|
||||
def add(self, pattern=None, **args):
|
||||
pattern = args.get("pattern", pattern)
|
||||
|
||||
def decorator(func):
|
||||
self.command_handler.incoming_commands[args['pattern']] = {
|
||||
self.command_handler.incoming_commands[pattern] = {
|
||||
"function": func,
|
||||
"noprefix": args.get('noprefix', False),
|
||||
"sudo": args.get('sudo', False)
|
||||
|
@@ -14,7 +14,7 @@ CONTENT_URL = "https://i.4cdn.org/{0}/{1}{2}"
|
||||
VALID_ENDS = (".mp4", ".jpg", ".jpeg", ".png", ".gif")
|
||||
|
||||
|
||||
@ldr.add(pattern="4c(f|)")
|
||||
@ldr.add("4c(f|)")
|
||||
async def fourchan(event):
|
||||
if event.pattern_match.group(1):
|
||||
as_file = True
|
||||
|
@@ -70,7 +70,7 @@ async def tori_atsume():
|
||||
return tori
|
||||
|
||||
|
||||
@ldr.add(pattern="shibe")
|
||||
@ldr.add("shibe")
|
||||
async def shibe(event):
|
||||
shibe_inu = await shibe_inu_atsume()
|
||||
|
||||
@@ -81,7 +81,7 @@ async def shibe(event):
|
||||
await event.reply(file=shibe_inu[0])
|
||||
|
||||
|
||||
@ldr.add(pattern="bird")
|
||||
@ldr.add("bird")
|
||||
async def bird(event):
|
||||
tori = await tori_atsume()
|
||||
|
||||
@@ -92,7 +92,7 @@ async def bird(event):
|
||||
await event.reply(file=tori[0])
|
||||
|
||||
|
||||
@ldr.add(pattern="(cat|pussy)")
|
||||
@ldr.add("(cat|pussy)")
|
||||
async def cat(event):
|
||||
neko = await neko_atsume(IMGPARAM)
|
||||
|
||||
@@ -103,7 +103,7 @@ async def cat(event):
|
||||
await event.reply(file=neko[0]["url"])
|
||||
|
||||
|
||||
@ldr.add(pattern="(cathd|pussyhd)")
|
||||
@ldr.add("(cathd|pussyhd)")
|
||||
async def cathd(event):
|
||||
neko = await neko_atsume(IMGPARAM)
|
||||
|
||||
@@ -114,7 +114,7 @@ async def cathd(event):
|
||||
await event.reply(file=neko[0]["url"], force_document=True)
|
||||
|
||||
|
||||
@ldr.add(pattern="(catgif|pussygif)")
|
||||
@ldr.add("(catgif|pussygif)")
|
||||
async def catgif(event):
|
||||
neko = await neko_atsume(GIFPARAM)
|
||||
|
||||
@@ -125,7 +125,7 @@ async def catgif(event):
|
||||
await event.reply(file=neko[0]["url"])
|
||||
|
||||
|
||||
@ldr.add(pattern="(dog|bitch)")
|
||||
@ldr.add("(dog|bitch)")
|
||||
async def dog(event):
|
||||
inu = await inu_atsume(IMGPARAM)
|
||||
|
||||
@@ -136,7 +136,7 @@ async def dog(event):
|
||||
await event.reply(file=inu[0]["url"])
|
||||
|
||||
|
||||
@ldr.add(pattern="(doghd|bitchhd)")
|
||||
@ldr.add("(doghd|bitchhd)")
|
||||
async def doghd(event):
|
||||
inu = await inu_atsume(IMGPARAM)
|
||||
|
||||
@@ -147,7 +147,7 @@ async def doghd(event):
|
||||
await event.reply(file=inu[0]["url"], force_document=True).delete()
|
||||
|
||||
|
||||
@ldr.add(pattern="(doggif|bitchgif)")
|
||||
@ldr.add("(doggif|bitchgif)")
|
||||
async def doggif(event):
|
||||
inu = await inu_atsume(GIFPARAM)
|
||||
|
||||
|
@@ -7,7 +7,7 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
@ldr.add(pattern="corona")
|
||||
@ldr.add("corona")
|
||||
async def corona(event):
|
||||
if event.args:
|
||||
with get(f"https://corona.lmao.ninja/v2/countries/{event.args}") as response:
|
||||
|
@@ -9,7 +9,7 @@ ldr = micro_bot.loader
|
||||
DAN_URL = "http://danbooru.donmai.us/posts.json"
|
||||
|
||||
|
||||
@ldr.add(pattern="dan(s|x|q|)(f|)")
|
||||
@ldr.add("dan(s|x|q|)(f|)")
|
||||
async def danbooru(event):
|
||||
if "x" in event.pattern_match.group(0):
|
||||
rating = "Rating:explicit"
|
||||
|
@@ -35,7 +35,7 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
@ldr.add(pattern="deepfry")
|
||||
@ldr.add("deepfry")
|
||||
async def deepfryer(event):
|
||||
try:
|
||||
frycount = int(event.args)
|
||||
|
@@ -14,7 +14,7 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
@ldr.add(pattern="speed", sudo=True)
|
||||
@ldr.add("speed", sudo=True)
|
||||
async def iamspeed(event):
|
||||
speed_message = await event.reply("`Running speed test…`")
|
||||
test = Speedtest()
|
||||
@@ -44,7 +44,7 @@ def speed_convert(size):
|
||||
return f"{round(size, 2)} {units[zero]}"
|
||||
|
||||
|
||||
@ldr.add(pattern="tts")
|
||||
@ldr.add("tts")
|
||||
async def text_to_speech(event):
|
||||
message, reply = await get_text_arg(event)
|
||||
|
||||
@@ -71,7 +71,7 @@ async def text_to_speech(event):
|
||||
await event.client.send_file(event.chat_id, tts_bytesio, voice_note=True, reply_to=reply or event)
|
||||
|
||||
|
||||
@ldr.add(pattern="ip")
|
||||
@ldr.add("ip")
|
||||
async def ip_lookup(event):
|
||||
ip, _ = await get_text_arg(event)
|
||||
|
||||
@@ -104,7 +104,7 @@ async def ip_lookup(event):
|
||||
await event.reply(text)
|
||||
|
||||
|
||||
@ldr.add(pattern="chatid")
|
||||
@ldr.add("chatid")
|
||||
async def chatidgetter(event):
|
||||
if event.is_reply:
|
||||
reply = await event.get_reply_message()
|
||||
@@ -118,7 +118,7 @@ async def chatidgetter(event):
|
||||
await event.reply(f"**Chat ID:**` {chat_id}`")
|
||||
|
||||
|
||||
@ldr.add(pattern="userid")
|
||||
@ldr.add("userid")
|
||||
async def useridgetter(event):
|
||||
if event.is_reply:
|
||||
reply = await event.get_reply_message()
|
||||
@@ -129,7 +129,7 @@ async def useridgetter(event):
|
||||
await event.reply(f"**User ID:**` {user_id}`")
|
||||
|
||||
|
||||
@ldr.add(pattern="profile")
|
||||
@ldr.add("profile")
|
||||
async def userprofilegetter(event):
|
||||
if event.args:
|
||||
try:
|
||||
@@ -160,7 +160,7 @@ async def userprofilegetter(event):
|
||||
await event.reply(f"**Full Name:** {userfullname}\n**Username:** @{username}\n**User ID:** {userid}")
|
||||
|
||||
|
||||
@ldr.add(pattern="stickpng")
|
||||
@ldr.add("stickpng")
|
||||
async def stickertopng(event):
|
||||
reply = await event.get_reply_message()
|
||||
|
||||
|
@@ -11,7 +11,7 @@ ldr = micro_bot.loader
|
||||
GEL_URL = "https://gelbooru.com/index.php"
|
||||
|
||||
|
||||
@ldr.add(pattern="gel(s|x|q|)(f|)")
|
||||
@ldr.add("gel(s|x|q|)(f|)")
|
||||
async def gelbooru(event):
|
||||
if "x" in event.pattern_match.group(0):
|
||||
rating = "Rating:explicit"
|
||||
|
@@ -18,7 +18,7 @@ owo_faces = "owo uwu owu uwo u-u o-o OwO UwU @-@ ;-; ;_; ._. (._.) (o-o) ('._.)
|
||||
zal_chars = " ̷̡̛̮͇̝͉̫̭͈͗͂̎͌̒̉̋́͜ ̵̠͕͍̩̟͚͍̞̳̌́̀̑̐̇̎̚͝ ̸̻̠̮̬̻͇͈̮̯̋̄͛̊͋̐̇͝͠ ̵̧̟͎͈̪̜̫̪͖̎͛̀͋͗́̍̊͠ ̵͍͉̟͕͇͎̖̹̔͌̊̏̌̽́̈́͊ͅ ̷̥͚̼̬̦͓͇̗͕͊̏͂͆̈̀̚͘̚ ̵̢̨̗̝̳͉̱̦͖̔̾͒͊͒̎̂̎͝ ̵̞̜̭̦̖̺͉̞̃͂͋̒̋͂̈́͘̕͜ ̶̢̢͇̲̥̗̟̏͛̇̏̊̑̌̔̚ͅͅ ̷̮͖͚̦̦̞̱̠̰̍̆̐͆͆͆̈̌́ ̶̲͚̪̪̪͍̹̜̬͊̆͋̄͒̾͆͝͝ ̴̨̛͍͖͎̞͍̞͕̟͑͊̉͗͑͆͘̕ ̶͕̪̞̲̘̬͖̙̞̽͌͗̽̒͋̾̍̀ ̵̨̧̡̧̖͔̞̠̝̌̂̐̉̊̈́́̑̓ ̶̛̱̼̗̱̙͖̳̬͇̽̈̀̀̎̋͌͝ ̷̧̺͈̫̖̖͈̱͎͋͌̆̈̃̐́̀̈".replace(" ", "")
|
||||
|
||||
|
||||
@ldr.add(pattern="cp")
|
||||
@ldr.add("cp")
|
||||
async def copypasta(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -33,7 +33,7 @@ async def copypasta(event):
|
||||
await event.reply(cp_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="mock")
|
||||
@ldr.add("mock")
|
||||
async def mock(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -45,7 +45,7 @@ async def mock(event):
|
||||
await event.reply(mock_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="vap")
|
||||
@ldr.add("vap")
|
||||
async def vapor(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -57,7 +57,7 @@ async def vapor(event):
|
||||
await event.reply(vapor_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="pop")
|
||||
@ldr.add("pop")
|
||||
async def popifycmd(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -69,7 +69,7 @@ async def popifycmd(event):
|
||||
await event.reply(pop_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="cheem")
|
||||
@ldr.add("cheem")
|
||||
async def cheemifycmd(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -81,7 +81,7 @@ async def cheemifycmd(event):
|
||||
await event.reply(cheems_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="zal")
|
||||
@ldr.add("zal")
|
||||
async def zalgo(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
@@ -93,7 +93,7 @@ async def zalgo(event):
|
||||
await event.reply(zalgo_text)
|
||||
|
||||
|
||||
@ldr.add(pattern="owo")
|
||||
@ldr.add("owo")
|
||||
async def owo(event):
|
||||
text_arg, reply = await get_text_arg(event)
|
||||
|
||||
|
@@ -110,7 +110,7 @@ async def bodyfetcher(event, sub):
|
||||
await event.reply(f"`Failed to find any valid content on `**r/{sub}**`!`")
|
||||
|
||||
|
||||
@ldr.add(pattern="redi")
|
||||
@ldr.add("redi")
|
||||
async def redimg(event):
|
||||
sub = event.args.replace(" ", "_")
|
||||
|
||||
@@ -120,7 +120,7 @@ async def redimg(event):
|
||||
await event.reply("Syntax: .redi <subreddit name>")
|
||||
|
||||
|
||||
@ldr.add(pattern="redt")
|
||||
@ldr.add("redt")
|
||||
async def redtit(event):
|
||||
sub = event.args.replace(" ", "_")
|
||||
|
||||
@@ -130,7 +130,7 @@ async def redtit(event):
|
||||
await event.reply("Syntax: .redt <subreddit name>")
|
||||
|
||||
|
||||
@ldr.add(pattern="redb")
|
||||
@ldr.add("redb")
|
||||
async def redbod(event):
|
||||
sub = event.args.replace(" ", "_")
|
||||
|
||||
@@ -140,22 +140,22 @@ async def redbod(event):
|
||||
await event.reply("Syntax: .redb <subreddit name>")
|
||||
|
||||
|
||||
@ldr.add(pattern="suffer")
|
||||
@ldr.add("suffer")
|
||||
async def makemesuffer(event):
|
||||
await imagefetcher(event, "MakeMeSuffer")
|
||||
|
||||
|
||||
@ldr.add(pattern="snafu")
|
||||
@ldr.add("snafu")
|
||||
async def coaxedintoasnafu(event):
|
||||
await imagefetcher(event, "CoaxedIntoASnafu")
|
||||
|
||||
|
||||
@ldr.add(pattern="aita")
|
||||
@ldr.add("aita")
|
||||
async def amitheasshole(event):
|
||||
await titlefetcher(event, "AmITheAsshole")
|
||||
|
||||
|
||||
@ldr.add(pattern="jon(x|)")
|
||||
@ldr.add("jon(x|)")
|
||||
async def imsorryjon(event):
|
||||
if "x" in event.pattern_match.group(0):
|
||||
sub = "ImReallySorryJon"
|
||||
@@ -165,11 +165,11 @@ async def imsorryjon(event):
|
||||
await imagefetcher(event, sub)
|
||||
|
||||
|
||||
@ldr.add(pattern="tihi")
|
||||
@ldr.add("tihi")
|
||||
async def thanksihateit(event):
|
||||
await imagefetcher(event, "TIHI")
|
||||
|
||||
|
||||
@ldr.add(pattern="gab")
|
||||
@ldr.add("gab")
|
||||
async def tenma(event):
|
||||
await imagefetcher(event, "tenma")
|
||||
|
@@ -10,7 +10,7 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
@ldr.add(pattern="reload", sudo=True)
|
||||
@ldr.add("reload", sudo=True)
|
||||
async def reload_modules(event):
|
||||
reload_msg = await event.reply("`Reloading modules…`")
|
||||
|
||||
@@ -25,14 +25,14 @@ async def reload_modules(event):
|
||||
pass
|
||||
|
||||
|
||||
@ldr.add(pattern="del")
|
||||
@ldr.add("del")
|
||||
async def delete_message(event):
|
||||
message_to_delete = await event.get_reply_message()
|
||||
if message_to_delete.from_id == (await event.client.get_me()).id:
|
||||
await message_to_delete.delete()
|
||||
|
||||
|
||||
@ldr.add(pattern="alive", sudo=True)
|
||||
@ldr.add("alive", sudo=True)
|
||||
async def alive(event):
|
||||
alive_format = "`μBot is running under {0}.\n\n" \
|
||||
"Version: {1}\n" \
|
||||
@@ -42,13 +42,13 @@ async def alive(event):
|
||||
await event.reply(alive_format.format(uname().node, ldr.botversion, version.__version__, python_version()))
|
||||
|
||||
|
||||
@ldr.add(pattern="shutdown", sudo=True)
|
||||
@ldr.add("shutdown", sudo=True)
|
||||
async def shutdown(event):
|
||||
await event.reply("`Goodbye…`")
|
||||
await micro_bot.stop_client()
|
||||
|
||||
|
||||
@ldr.add(pattern="ping")
|
||||
@ldr.add("ping")
|
||||
async def ping(event):
|
||||
start = time_ns()
|
||||
ping_msg = await event.reply("`Ping…`")
|
||||
@@ -56,6 +56,6 @@ async def ping(event):
|
||||
await ping_msg.edit(f"`Ping… Pong! -> `**{time_taken_ms}**`ms`")
|
||||
|
||||
|
||||
@ldr.add(pattern="repo")
|
||||
@ldr.add("repo")
|
||||
async def bot_repo(event):
|
||||
await event.reply("https://github.com/Nick80835/microbot")
|
||||
|
@@ -12,7 +12,7 @@ UD_QUERY_URL = 'http://api.urbandictionary.com/v0/define'
|
||||
UD_RANDOM_URL = 'http://api.urbandictionary.com/v0/random'
|
||||
|
||||
|
||||
@ldr.add(pattern="ud")
|
||||
@ldr.add("ud")
|
||||
async def urban_dict(event):
|
||||
udquery = event.args
|
||||
|
||||
|
@@ -7,7 +7,7 @@ from ubot.micro_bot import micro_bot
|
||||
ldr = micro_bot.loader
|
||||
|
||||
|
||||
@ldr.add(pattern="yt")
|
||||
@ldr.add("yt")
|
||||
async def youtube_cmd(event):
|
||||
video = pafy.new(event.args)
|
||||
video_stream = video.getbest()
|
||||
@@ -17,7 +17,7 @@ async def youtube_cmd(event):
|
||||
await event.reply(f"`Download failed: `[URL]({video_stream.url})")
|
||||
|
||||
|
||||
@ldr.add(pattern="yta")
|
||||
@ldr.add("yta")
|
||||
async def youtube_audio_cmd(event):
|
||||
video = pafy.new(event.args)
|
||||
video_stream = video.getbestaudio()
|
||||
|
Reference in New Issue
Block a user