add some custom plugins for my use. Thank you @TelethonChat

pull/16/head
Shrimadhav U K 2018-08-06 12:13:49 +05:30
parent 3efb5a09a0
commit 28e4b98b45
9 changed files with 150 additions and 3 deletions

View File

@ -10,7 +10,7 @@ async def _(event):
if event.fwd_from:
return
await event.delete()
mentions = "@all"
mentions = "@tagall"
chat = await event.get_input_chat()
async for x in borg.iter_participants(chat, 100):
mentions += f"[\u2063](tg://user?id={x.id})"

16
stdplugins/delmsg.py Normal file
View File

@ -0,0 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=".delmsg", outgoing=True))
async def _(event):
if event.fwd_from:
return
i = 1
async for message in borg.iter_messages(event.chat_id, from_user="me"):
i = i + 1
await message.delete()
await event.delete()

19
stdplugins/get_admin.py Normal file
View File

@ -0,0 +1,19 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from telethon.tl.types import ChannelParticipantsAdmins
@borg.on(events.NewMessage(pattern=".get_admin", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.delete()
mentions = "**Admins in this Chat**: \n"
chat = await event.get_input_chat()
async for x in borg.iter_participants(chat, filter=ChannelParticipantsAdmins):
mentions += f"\n[{x.first_name}](tg://user?id={x.id})"
await borg.send_message(
chat, mentions, reply_to=event.message.reply_to_msg_id)

13
stdplugins/get_id.py Normal file
View File

@ -0,0 +1,13 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=r".get_id", outgoing=True))
async def _(event):
if event.fwd_from:
return
chat = await event.get_input_chat()
await event.edit("-100" + str(chat.channel_id))

40
stdplugins/kickdas.py Normal file
View File

@ -0,0 +1,40 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChannelBannedRights
from datetime import datetime, timedelta
from telethon.errors import UserAdminInvalidError
@borg.on(events.NewMessage(pattern=".kickdas", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Getting Participant Lists. This might take some time ...")
p = await borg.get_participants(event.chat_id, aggressive=True)
await event.edit("Searching through {} users for deleted accounts ...".format(len(p)))
c = 0
e = []
for i in p:
#
# Note that it's "reversed". You must set to ``True`` the permissions
# you want to REMOVE, and leave as ``None`` those you want to KEEP.
rights = ChannelBannedRights(
until_date=None,
view_messages=True
)
if i.deleted:
try:
await borg(EditBannedRequest(event.chat_id, i, rights))
c = c + 1
except UserAdminInvalidError as exc:
await event.edit("I need admin priveleges to perform this action!")
break
except:
e.append("ERROR")
await event.edit("Kicked {} / {} users".format(c, len(p)))

16
stdplugins/ping.py Normal file
View File

@ -0,0 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from datetime import datetime
@borg.on(events.NewMessage(pattern=r".ping", outgoing=True))
async def _(event):
if event.fwd_from:
return
start = datetime.now()
await event.edit('Pong!')
end = datetime.now()
ms = (end - start).microseconds / 1000
await event.edit('Pong!\n%sms' % (ms))

20
stdplugins/purge.py Normal file
View File

@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=".purge", outgoing=True))
async def _(event):
if event.fwd_from:
return
i = 1
msgs = []
async for message in borg.iter_messages(event.chat_id, min_id=event.reply_to_msg_id):
i = i + 1
msgs.append(message)
if len(msgs) <= 100:
await borg.delete_messages(event.chat_id, msgs)
msgs = []
await event.delete()

View File

@ -7,7 +7,7 @@ from telethon.tl import types, functions
HEADER = "[[sed]]\n"
KNOWN_RE_BOTS = re.compile(
r'(regex|moku|BananaButler_|rgx|l4mR)bot',
r'(regex|moku|BananaButler_|rgx|l4mR|kochu|BanhammerMarie_)bot',
flags=re.IGNORECASE
)
@ -91,6 +91,7 @@ async def on_regex(event):
return
if not event.is_private and\
await group_has_sedbot(await event.get_input_chat()):
await event.edit("This group has a sed bot. Ignoring this message!")
return
chat_id = utils.get_peer_id(await event.get_input_chat())
@ -104,6 +105,6 @@ async def on_regex(event):
)
last_msgs[chat_id].appendleft(out)
elif s is not None:
await event.reply(s)
await event.edit(s)
raise events.StopPropagation

View File

@ -0,0 +1,22 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import urbandict
@borg.on(events.NewMessage(pattern="^.ud (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("processing...")
str = event.pattern_match.group(1)
try:
mean = urbandict.define(str)
if len(mean) > 0:
await event.edit('Text: **'+str+'**\n\nMeaning: **'+mean[0]['def']+'**\n\n'+'Example: \n__'+mean[0]['example']+'__')
else:
await event.edit("No result found for **"+str+"**")
except e:
await event.edit("No result found for **"+str+"**")