make things easier to develop in future

This commit is contained in:
Danial Behzadi 2021-06-01 05:03:52 +04:30
parent 36a2257a95
commit 2ab3e0181c

View file

@ -26,7 +26,7 @@ def get_text_and_media(message):
elif message['media']:
text = message['caption']
media = message.download()
return text, media
return splitext(text), media
def connect():
@ -40,23 +40,15 @@ def connect():
return mastodon
def section(text: str, part: int):
def splitext(text: str):
'''
return the text in sections
for long texts
split text into parts
'''
limit = config.character_limit
return text[limit*part:limit*(part+1)]
def continued(text: str, part: int):
'''
specifies if text is continued
'''
limit = config.character_limit
if len(text) <= limit*(part+1):
return False
return True
result = [
text[limit*part:limit*(part+1)]
for part in range(len(text)/limit+1)]
return result
def main():
@ -73,19 +65,17 @@ def main():
if chat['type'] == 'channel':
if chat['username'] == config.channel_id:
text, media = get_text_and_media(message)
part = 0
if media:
mid = mastodon.media_post(media)
os.remove(media)
else:
mid = None
post = mastodon.status_post(
section(text, part),
text[0],
media_ids=mid)
while continued(text, part):
part += 1
for part in range(1, len(text)):
post = mastodon.status_post(
section(text, part),
text[part],
in_reply_to_id=post['id'])
telegram.start()