-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgg.gg.py
More file actions
65 lines (51 loc) · 2.32 KB
/
gg.gg.py
File metadata and controls
65 lines (51 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# Friendly Telegram (telegram userbot)
# Copyright (C) 2018-2020 @DneZyeK | sub to @KeyZenD
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
from .. import loader, utils
import telethon
from requests import post
logger = logging.getLogger(__name__)
async def register(cb):
cb(WhoIsMod())
@loader.tds
class GGdotGGMod(loader.Module):
"""Сокращение ссылок через сервис gg.gg"""
strings = {
"name": "gg.gg",
"some_rong": "<b>Ты делаешь что-то не так!\nНапиши</b> <code>.help gg.gg</code> <b>для информации.</b>"
}
async def client_ready(self, client, db):
self.client = client
async def ggcmd(self, message):
""".gg <длинная ссылка или реплай на ссылку> """
m_text = utils.get_args_raw(message)
if not m_text:
reply = await message.get_reply_message()
if not reply:
await utils.answer(message, self.strings["some_rong"])
return
long_url = reply.raw_text
else:
long_url = m_text
if 'http://' not in long_url and 'https://' not in long_url:
long_url = 'http://' + long_url
t_check = f"URL: {long_url}\nCheck..."
await utils.answer(message, t_check)
check = post('http://gg.gg/check', data={'custom_path': None, 'use_norefs': '0', 'long_url': long_url, 'app': 'site', 'version': '0.1'}).text
if check != "ok":
await utils.answer(message, check)
return
await utils.answer(message, "Create...")
short = post('http://gg.gg/create', data={'custom_path': None, 'use_norefs': '0', 'long_url': long_url, 'app': 'site', 'version': '0.1'}).text
await utils.answer(message, short)