forked from AnimeKaizoku/EnterpriseALRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
170 lines (142 loc) · 9.66 KB
/
__init__.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import logging
import os
import sys
import time
from typing import List
import spamwatch
import telegram.ext as tg
from telethon import TelegramClient
from telethon.sessions import MemorySession
from configparser import ConfigParser
from ptbcontrib.postgres_persistence import PostgresPersistence
from logging.config import fileConfig
StartTime = time.time()
flag = """
\033[37m┌─────────────────────────────────────────────┐\033[0m\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│\n\033[37m│\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[97;107m:::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[44m\033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[97m★\033[0m\033[44m \033[0m\033[91;101m#########################\033[0m\033[37m│ \033[1mUnited we stand, Divided we fall\033[0m\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│ \033[1mKigyo Project, a tribute to USS Enterprise.\033[0m\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m│\033[97;107m:::::::::::::::::::::::::::::::::::::::::::::\033[0m\033[37m│\n\033[37m│\033[91;101m#############################################\033[0m\033[37m│\n\033[37m└─────────────────────────────────────────────┘\033[0m\n
"""
def get_user_list(key):
# Import here to evade a circular import
from tg_bot.modules.sql import nation_sql
royals = nation_sql.get_royals(key)
return [a.user_id for a in royals]
# enable logging
fileConfig('logging.ini')
#print(flag)
log = logging.getLogger('[Enterprise]')
logging.getLogger('ptbcontrib.postgres_persistence.postgrespersistence').setLevel(logging.WARNING)
log.info("[KIGYO] Kigyo is starting. | An Eagle Union Project. | Licensed under GPLv3.")
log.info("[KIGYO] Not affiliated to Azur Lane or Yostar in any way whatsoever.")
log.info("[KIGYO] Project maintained by: github.com/Dank-del (t.me/dank_as_fuck)")
# if version < 3.6, stop bot.
if sys.version_info[0] < 3 or sys.version_info[1] < 7:
log.error(
"[KIGYO] You MUST have a python version of at least 3.7! Multiple features depend on this. Bot quitting."
)
quit(1)
parser = ConfigParser()
parser.read("config.ini")
kigconfig = parser["kigconfig"]
class KigyoINIT:
def __init__(self, parser: ConfigParser):
self.parser = parser
self.SYS_ADMIN: int = self.parser.getint('SYS_ADMIN', 0)
self.OWNER_ID: int = self.parser.getint('OWNER_ID')
self.OWNER_USERNAME: str = self.parser.get('OWNER_USERNAME', None)
self.APP_ID: str = self.parser.getint("APP_ID")
self.API_HASH: str = self.parser.get("API_HASH")
self.WEBHOOK: bool = self.parser.getboolean('WEBHOOK', False)
self.URL: str = self.parser.get('URL', None)
self.CERT_PATH: str = self.parser.get('CERT_PATH', None)
self.PORT: int = self.parser.getint('PORT', None)
self.INFOPIC: bool = self.parser.getboolean('INFOPIC', False)
self.DEL_CMDS: bool = self.parser.getboolean("DEL_CMDS", False)
self.STRICT_GBAN: bool = self.parser.getboolean("STRICT_GBAN", False)
self.ALLOW_EXCL: bool = self.parser.getboolean("ALLOW_EXCL", False)
self.CUSTOM_CMD: List[str] = ['/', '!']
self.BAN_STICKER: str = self.parser.get("BAN_STICKER", None)
self.TOKEN: str = self.parser.get("TOKEN")
self.DB_URI: str = self.parser.get("SQLALCHEMY_DATABASE_URI")
self.LOAD = self.parser.get("LOAD").split()
self.LOAD: List[str] = list(map(str, self.LOAD))
self.MESSAGE_DUMP: int = self.parser.getint('MESSAGE_DUMP', None)
self.GBAN_LOGS: int = self.parser.getint('GBAN_LOGS', None)
self.NO_LOAD = self.parser.get("NO_LOAD").split()
self.NO_LOAD: List[str] = list(map(str, self.NO_LOAD))
self.spamwatch_api: str = self.parser.get('spamwatch_api', None)
self.CASH_API_KEY: str = self.parser.get('CASH_API_KEY', None)
self.TIME_API_KEY: str = self.parser.get('TIME_API_KEY', None)
self.WALL_API: str = self.parser.get('WALL_API', None)
self.LASTFM_API_KEY: str = self.parser.get('LASTFM_API_KEY', None)
self.CF_API_KEY: str = self.parser.get("CF_API_KEY", None)
self.bot_id = 0 #placeholder
self.bot_name = "Kigyo" #placeholder
self.bot_username = "KigyoRobot" #placeholder
self.DEBUG: bool = self.parser.getboolean("IS_DEBUG", False)
self.DROP_UPDATES: bool = self.parser.getboolean("DROP_UPDATES", True)
self.BOT_API_URL: str = self.parser.get('BOT_API_URL', "https://api.telegram.org/bot")
self.BOT_API_FILE_URL: str = self.parser.get('BOT_API_FILE_URL', "https://api.telegram.org/file/bot")
def init_sw(self):
if self.spamwatch_api is None:
log.warning("SpamWatch API key is missing! Check your config.ini")
return None
else:
try:
sw = spamwatch.Client(spamwatch_api)
return sw
except:
sw = None
log.warning("Can't connect to SpamWatch!")
return sw
KInit = KigyoINIT(parser=kigconfig)
SYS_ADMIN = KInit.SYS_ADMIN
OWNER_ID = KInit.OWNER_ID
OWNER_USERNAME = KInit.OWNER_USERNAME
APP_ID = KInit.APP_ID
API_HASH = KInit.API_HASH
WEBHOOK = KInit.WEBHOOK
URL = KInit.URL
CERT_PATH = KInit.CERT_PATH
PORT = KInit.PORT
INFOPIC = KInit.INFOPIC
DEL_CMDS = KInit.DEL_CMDS
ALLOW_EXCL = KInit.ALLOW_EXCL
CUSTOM_CMD = KInit.CUSTOM_CMD
BAN_STICKER = KInit.BAN_STICKER
TOKEN = KInit.TOKEN
DB_URI = KInit.DB_URI
LOAD = KInit.LOAD
MESSAGE_DUMP = KInit.MESSAGE_DUMP
GBAN_LOGS = KInit.GBAN_LOGS
NO_LOAD = KInit.NO_LOAD
SUDO_USERS = [OWNER_ID] + get_user_list("sudos")
DEV_USERS = [OWNER_ID] + get_user_list("devs")
SUPPORT_USERS = get_user_list("supports")
SARDEGNA_USERS = get_user_list("sardegnas")
WHITELIST_USERS = get_user_list("whitelists")
SPAMMERS = get_user_list("spammers")
spamwatch_api = KInit.spamwatch_api
CASH_API_KEY = KInit.CASH_API_KEY
TIME_API_KEY = KInit.TIME_API_KEY
WALL_API = KInit.WALL_API
LASTFM_API_KEY = KInit.LASTFM_API_KEY
CF_API_KEY = KInit.CF_API_KEY
SPB_MODE = kigconfig.getboolean('SPB_MODE', False)
# SpamWatch
sw = KInit.init_sw()
from tg_bot.modules.sql import SESSION
if not KInit.DROP_UPDATES:
updater = tg.Updater(token=TOKEN, base_url=KInit.BOT_API_URL, base_file_url=KInit.BOT_API_FILE_URL, workers=min(32, os.cpu_count() + 4), request_kwargs={"read_timeout": 10, "connect_timeout": 10}, persistence=PostgresPersistence(session=SESSION))
else:
updater = tg.Updater(token=TOKEN, base_url=KInit.BOT_API_URL, base_file_url=KInit.BOT_API_FILE_URL, workers=min(32, os.cpu_count() + 4), request_kwargs={"read_timeout": 10, "connect_timeout": 10})
telethn = TelegramClient(MemorySession(), APP_ID, API_HASH)
dispatcher = updater.dispatcher
# Load at end to ensure all prev variables have been set
from tg_bot.modules.helper_funcs.handlers import CustomCommandHandler
if CUSTOM_CMD and len(CUSTOM_CMD) >= 1:
tg.CommandHandler = CustomCommandHandler
def spamfilters(text, user_id, chat_id):
# print("{} | {} | {}".format(text, user_id, chat_id))
if int(user_id) not in SPAMMERS:
return False
print("This user is a spammer!")
return True