-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendMessage.py
132 lines (119 loc) · 5.5 KB
/
sendMessage.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import time
class sendMessage():
chatID = 0
bot = ""
list_output = [] ##Beinhaltet alle Encounters welche versendet wurden
list_message_ID = []
list_lists_ID = []
overview_old = ""
overview_old2= ""
overviewId = 0
overviewId2= 0
areaName = ""
areaNumber = ""
def send(self,latitude,longitude,bolt_line,normal_line,gmaps,stop,venue):
try:
if venue == True:
id = self.bot.send_venue(self.singlechatID,latitude,longitude,bolt_line,normal_line,disable_notification=True)
else:
id = self.bot.send_message(self.singlechatID,gmaps,parse_mode='HTML',disable_web_page_preview=False,disable_notification=True)
self.list_output.append(stop)
self.list_message_ID.append(id.message_id)
outF = open(self.areaName+self.areaNumber+"/output.txt","w")
outF.writelines(str(self.list_message_ID))
outF.close()
return id.message_id
except:
print(".................... wait 30 seconds, too many messages")
sleep = time.sleep(30)
return sleep
def sendOverview(self,message,message2,text):
print("\nmessage1 ==> " + str(len(message)) + " (" + str(len(self.overview_old)) + ")")
print("message2 ==> " + str(len(message2)) + " (" + str(len(self.overview_old2)) + ")")
## Wenn der Quest Zähler sich erhöht, liste 1 nur editieren
if len(self.overview_old) == len(message) and not message == self.overview_old:
self.bot.edit_message_text(message,chat_id=self.chatID, message_id=self.overviewId.message_id, parse_mode='HTML',disable_web_page_preview=True)
self.overview_old = message
## liste 1 & 2 haben sich nicht verändert ==> return
if self.overview_old == message and self.overview_old2 == message2:
return
## alte liste 2 ist vorhanden, hat aber keinen inhalt mehr ==> löschen
if not message2 and self.overview_old2:
try:
self.bot.delete_message(self.chatID,self.overviewId2.message_id)
self.list_lists_ID.remove(self.overviewId2.message_id)
self.overview_old2 = message2
except:
print("Liste 2 konnte nicht entfernt werden !")
## liste 1 oder 2 hat sich verändert ==> neu senden
try:
if not message:
message = text
self.bot.edit_message_text(message,chat_id=self.chatID, message_id=self.overviewId.message_id, parse_mode='HTML',disable_web_page_preview=True)
self.overview_old = ""
self.clearOldList(self.areaName,self.areaNumber,self.list_lists_ID)
return
if self.chatID != self.singlechatID:
self.bot.edit_message_text(message,chat_id=self.chatID, message_id=self.overviewId.message_id, parse_mode='HTML',disable_web_page_preview=True)
else:
self.bot.delete_message(self.chatID,self.overviewId.message_id)
self.list_lists_ID.remove(self.overviewId.message_id)
self.overviewId = self.bot.send_message(self.chatID,message,parse_mode='HTML',disable_web_page_preview=True)
self.list_lists_ID.append(self.overviewId.message_id)
self.overview_old = message
except:
try:
self.overviewId = self.bot.send_message(self.chatID,message,parse_mode='HTML',disable_web_page_preview=True)
self.list_lists_ID.append(self.overviewId.message_id)
self.overview_old = message
except:
print("no message")
## liste 2 versenden wenn vorhanden
if message2 and self.overview_old:
try:
if self.chatID != self.singlechatID:
self.bot.edit_message_text(message2,chat_id=self.chatID, message_id=self.overviewId2.message_id, parse_mode='HTML',disable_web_page_preview=True)
else:
self.bot.delete_message(self.chatID,self.overviewId2.message_id)
self.list_lists_ID.remove(self.overviewId2.message_id)
self.overviewId2 = self.bot.send_message(self.chatID,message2,parse_mode='HTML',disable_web_page_preview=True)
self.list_lists_ID.append(self.overviewId2.message_id)
self.overview_old2 = message2
except:
try:
self.overviewId2 = self.bot.send_message(self.chatID,message2,parse_mode='HTML',disable_web_page_preview=True)
self.list_lists_ID.append(self.overviewId2.message_id)
self.overview_old2 = message2
except:
print("no message_2")
self.clearOldList(self.areaName,self.areaNumber,self.list_lists_ID)
def clearOldList (self, areaName, areaNumber, list_lists_ID):
filename_list_lists_ID = self.areaName+self.areaNumber+"/lists.txt"
outF = open(filename_list_lists_ID,"w")
outF.writelines(str(self.list_lists_ID))
outF.close()
def clearOutputList(self,encounter):
i = 0
print(self.areaName+self.areaNumber+" Checke Outputliste")
for encount in self.list_output:
if not encounter.__contains__(encount):
try:
print(self.areaName+self.areaNumber+" Entferne Nachricht")
self.bot.delete_message(self.singlechatID,self.list_message_ID[i])
self.list_message_ID.__delitem__(i)
self.list_output.__delitem__(i)
except:
print(self.areaName+self.areaNumber+" Nachricht konnte nicht entfernt werden")
i +=1
outF = open(self.areaName+self.areaNumber+"/output.txt","w")
outF.writelines(str(self.list_message_ID))
outF.close()
def setConfig(self,token,singlechatID,chatID,areaName,areaNumber):
self.areaNumber = areaNumber
self.areaName = areaName
self.singlechatID = singlechatID
self.chatID = chatID
self.bot = telebot.TeleBot(token)