Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Added !neko and migrated to 1.0 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ venv.bak/

# mypy
.mypy_cache/
.idea/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Name | Description | Usage
[**welcome**](plugins/welcome), by [delivrance](//github.com/delivrance) | Greet new members with a welcome message | Run and wait for new members to join your groups
[**eval**](plugins/eval), by [Furoin](//github.com/Furoin) | Evaluate a Python expression and send the result | Example: `!eval 1+2+3`
[**replace**](plugins/replace), by [brightside](//github.com/bright5ide) | Search and Replace a part of a message to suggest user if he meant something else | Reply to a group chat text message with `!r <old>/<new>`
[**neko**](plugins/neko), by [GodSaveTheDoge](//github.com/GodSaveTheDoge) | Paste something to nekobin.com and send the link | Reply to a text message with `!neko`
18 changes: 6 additions & 12 deletions plugins/eval/eval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2018 Furoin <https://github.com/furoin>
# Copyright (c) 2020 Furoin <https://github.com/furoin>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,15 +20,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyrogram import Client, Filters
from pyrogram import Client, filters

RUNNING = "**Eval Expression:**\n```{}```\n**Running...**"
ERROR = "**Eval Expression:**\n```{}```\n**Error:**\n```{}```"
SUCCESS = "**Eval Expression:**\n```{}```\n**Success**"
RESULT = "**Eval Expression:**\n```{}```\n**Result:**\n```{}```"


@Client.on_message(Filters.command("eval", prefix="!"))
@Client.on_message(filters.command("eval", prefixes=("!",)))
def eval_expression(client, message):
expression = " ".join(message.command[1:])

Expand All @@ -39,20 +39,14 @@ def eval_expression(client, message):
result = eval(expression)
except Exception as error:
client.edit_message_text(
m.chat.id,
m.message_id,
ERROR.format(expression, error)
m.chat.id, m.message_id, ERROR.format(expression, error)
)
else:
if result is None:
client.edit_message_text(
m.chat.id,
m.message_id,
SUCCESS.format(expression)
m.chat.id, m.message_id, SUCCESS.format(expression)
)
else:
client.edit_message_text(
m.chat.id,
m.message_id,
RESULT.format(expression, result)
m.chat.id, m.message_id, RESULT.format(expression, result)
)
12 changes: 5 additions & 7 deletions plugins/haste/haste.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2018 Dan Tès <https://github.com/delivrance>
# Copyright (c) 2020 Dan Tès <https://github.com/delivrance>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,12 +22,12 @@

import requests

from pyrogram import Client, Filters
from pyrogram import Client, filters

BASE = "https://hastebin.com"


@Client.on_message(Filters.command("haste", prefix="!") & Filters.reply)
@Client.on_message(filters.command("haste", prefixes=("!",)) & filters.reply)
def haste(client, message):
reply = message.reply_to_message

Expand All @@ -37,11 +37,9 @@ def haste(client, message):
message.delete()

result = requests.post(
"{}/documents".format(BASE),
data=reply.text.encode("UTF-8")
"{}/documents".format(BASE), data=reply.text.encode("UTF-8")
).json()

message.reply(
"{}/{}.py".format(BASE, result["key"]),
reply_to_message_id=reply.message_id
"{}/{}.py".format(BASE, result["key"]), reply_to_message_id=reply.message_id
)
47 changes: 47 additions & 0 deletions plugins/neko/neko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# MIT License
#
# Copyright (c) 2020 GodSaveTheDoge <https://github.com/GodSaveTheDoge>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import requests

from pyrogram import Client, filters
from pyrogram.types import Message

BASE = "https://nekobin.com"


@Client.on_message(filters.command("neko", prefixes=("!",)) & filters.reply)
def neko(client: Client, message: Message):
reply = message.reply_to_message

if reply.text is None:
return

message.delete()

result = requests.post(
"{}/api/documents".format(BASE), data=dict(content=reply.text.encode("UTF-8"))
).json()

message.reply(
"{}/{}.py".format(BASE, result["result"]["key"]),
reply_to_message_id=reply.message_id,
)
1 change: 1 addition & 0 deletions plugins/neko/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
20 changes: 14 additions & 6 deletions plugins/replace/replace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2018 BrightSide <https://github.com/bright5ide>
# Copyright (c) 2020 BrightSide <https://github.com/bright5ide>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,13 +20,21 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyrogram import Client, Filters

@Client.on_message(Filters.command("r", prefix="!") & Filters.reply & ~Filters.edited & Filters.group)
from pyrogram import Client, filters


@Client.on_message(
filters.command("r", prefixes=("!",))
& filters.reply
& ~filters.edited
& filters.group
)
def r(client, message):
if len(message.command) > 1:
colength = len("r") + len("!")
query = str(message.text)[colength:].lstrip()
eventsplit=query.split("/")
result="**You mean:**\n{}".format(message.reply_to_message.text.replace(eventsplit[0],eventsplit[1]))
eventsplit = query.split("/")
result = "**You mean:**\n{}".format(
message.reply_to_message.text.replace(eventsplit[0], eventsplit[1])
)
client.edit_message_text(message.chat.id, message.message_id, result)
10 changes: 5 additions & 5 deletions plugins/welcome/welcome.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2018 Dan Tès <https://github.com/delivrance>
# Copyright (c) 2020 Dan Tès <https://github.com/delivrance>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,16 +20,16 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyrogram import Client, Emoji, Filters
from pyrogram import Client, emoji, filters

MENTION = "[{}](tg://user?id={})"
MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!"

chats_filter = Filters.chat(["PyrogramChat", "PyrogramLounge"])
chats_filter = filters.chat(["PyrogramChat", "PyrogramLounge"])


@Client.on_message(chats_filter & Filters.new_chat_members)
@Client.on_message(chats_filter & filters.new_chat_members)
def welcome(client, message):
new_members = [MENTION.format(i.first_name, i.id) for i in message.new_chat_members]
text = MESSAGE.format(Emoji.SPARKLES, ", ".join(new_members))
text = MESSAGE.format(emoji.SPARKLES, ", ".join(new_members))
message.reply(text, disable_web_page_preview=True)