-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_pusher.py
More file actions
189 lines (163 loc) · 5.35 KB
/
message_pusher.py
File metadata and controls
189 lines (163 loc) · 5.35 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# coding=utf-8
from colours import colour
from getpass import getuser
from core import telegram_bot_api
import configparser as cfg
import time
import random
import platform
import os
import textf
detected_OS = platform.system()
prgm_path = ""
if detected_OS == "Windows":
if os.environ.get("PROGRAMFILES(X86)") is None:
prgm_path = os.environ.get("PROGRAMFILES")
else:
prgm_path = os.environ.get("PROGRAMFILES(X86)")
config_path = ["config.cfg", f"/home/{getuser()}/.local/share/telegram_bot/config.cfg", f"{prgm_path}\\GourSE\\telegram_bot\\"]
# Get config file for settings
config = cfg.ConfigParser()
if detected_OS == "Windows":
try:
bot = telegram_bot_api(config_path[0])
config.read(config_path[0])
except:
bot = telegram_bot_api(config_path[2])
config.read(config_path[2])
else:
try:
bot = telegram_bot_api(config_path[0])
config.read(config_path[0])
except:
bot = telegram_bot_api(config_path[1])
config.read(config_path[1])
alert = False
try:
is_send_typing = config.get("settings", "send_typing")
except:
alert = True
is_send_typing = True
try:
is_markdown = config.get("settings", "use_markdown")
except:
alert = True
is_markdown = False
if alert:
print(f"{colour.RED}there is a new version of config.cfg, will set some setings to default{colour.reset}")
else:
pass
# set user settings
if is_send_typing.lower() == "true":
is_send_typing = True
elif is_send_typing.lower() == "false":
is_send_typing = False
if is_markdown.lower() == "true":
is_markdown = True
elif is_markdown.lower() == "false":
is_markdown = False
def message_type_prompt(last_chat_id=None):
fed = input("\nMessage types:\ntext(t)\nsticker(s)\nEnter message type > $ ")
fed = fed.lower()
if fed == "text" or fed == "t" or fed == "1":
return "text"
elif fed == "sticker" or fed == "s" or fed == "2":
return "sticker"
elif fed == ":q":
print(f"{colour.GREEN}abort{colour.reset}\n")
master(last_chat_id)
else:
print("\n{}{} is not a message type{}\n".format(colour.RED, fed, colour.reset))
time.sleep(0.5)
return message_type_prompt(last_chat_id)
def sticker_prompt(chat_id):
success = None
fed = input("Enter sticker ID > $ ")
if fed == ":q":
print(f"{colour.GREEN}abort{colour.reset}\n")
time.sleep(0.5)
master(chat_id)
else:
try:
success = bot.send_sticker(chat_id, fed)
if success:
print("sticker sent")
else:
print("sticker not sent\n")
sticker_prompt(chat_id)
except:
print("Something went wrong\nMake sure the sticker ID is correct\n")
time.sleep(0.5)
sticker_prompt(chat_id)
def send_typing(text, chat_id):
lenght = len(text)
loop = int(lenght * 0.2)
while loop > 0:
loop -= 1
bot.send_chat_action(chat_id, "typing")
def text_prompt(chat_id):
success = None
global is_markdown
global is_send_typing
fed = input("Enter text message > $ ")
if fed == ":q":
print(f"{colour.GREEN}abort{colour.reset}\n")
master(chat_id)
else:
fedf = textf.hex(fed)
try:
if is_send_typing:
send_typing(fed, chat_id)
success = bot.send_message(chat_id, fedf, is_markdown=is_markdown)
if success:
print(f"message: \"{fed}\" sent")
else:
print(f"message: \"{fed}\" not send\n")
text_prompt(chat_id)
else:
success = bot.send_message(chat_id, fedf, None, is_markdown)
if success:
print(f"message: \"{fed}\" sent")
else:
print(f"message: \"{fed}\" not send\n")
text_prompt(chat_id)
except Exception as ERROR:
print(f"\nSomething went wrong, more info:\n{ERROR}\n\n")
time.sleep(0.5)
text_prompt(chat_id)
def master(last_chat_id=None):
if last_chat_id is not None:
fed = input("Use previous chat ID?(Y/n) > $ ")
fedf = fed[0].lower()
# print(fed)
if fedf == "y":
chat_id = last_chat_id
elif fedf == "n":
chat_id = input("Ener chat ID: ")
elif fed == ":q":
print(f"{colour.GREEN}quit{colour.reset}\n")
os._exit(1)
else:
print(f"{colour.RED}{fed} is not a valid answer{colour.reset}\nuse (Y/n)\n")
time.sleep(1)
master(last_chat_id)
else:
while True:
chat_id = input("Ener chat ID > $ ")
if chat_id == "":
print(f"{colour.RED}you entered nothing{colour.reset}\n")
time.sleep(1)
elif chat_id == ":q":
print(f"{colour.GREEN}quit{colour.reset}\n")
os._exit(1)
else:
break
message_type = message_type_prompt(last_chat_id)
print("You are going to send {} message(s) to chat id: {}".format(message_type, chat_id))
if message_type == "sticker":
sticker_prompt(chat_id)
elif message_type == "text":
text_prompt(chat_id)
else:
print(f"{colour.RED}ERROR: MESSAGE_TYPE_INVALID{colour.reset}")
master()