Skip to content

updates on main.py #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import random
import os
from asyncio import sleep
from pprint import pprint

from telethon import TelegramClient, events, utils
Expand Down Expand Up @@ -32,35 +33,36 @@
@client.on(events.NewMessage)
async def handle_new_message(event):

me = await client.get_me().username
from_ = await event.client.get_entity(event.from_id) # this lookup will be cached by telethon
me = await client.get_me()
username = me.username
sender = await event.get_sender() # this lookup will be cached by telethon
to_ = await event.client.get_entity(event.message.to_id)

needToProceed = from_.is_self if debug_mode else not from_.is_self and (event.is_private or re.search("@"+me.username,event.raw_text))
needToProceed = sender.is_self if debug_mode else not sender.is_self and (event.is_private or re.search("@"+me.username,event.raw_text))
if needToProceed: # only auto-reply to private chats: # only auto-reply to private chats
if not from_.bot and event: # don't auto-reply to bots
if not sender.bot and event: # don't auto-reply to bots
print(time.asctime(), '-', event.message) # optionally log time and message
time.sleep(1) # pause for 1 second to rate-limit automatic replies
await sleep(1) # pause for 1 second to rate-limit automatic replies
message = ""
senderList.append(to_.id)
if senderList.count(to_.id) < 2:
message = f"""**AUTO REPLY**
\nHi @{from_.username},
\nHi @{sender.username},
\n\nMohon maaf boss saya sedang offline, mohon tunggu sebentar.
\nSilahkan lihat-lihat [imacakes](https://www.instagram.com/ima_cake_cirebon) dulu untuk cuci mata.
\n\n**AUTO REPLY**"""
elif senderList.count(to_.id) < 3:
message = f"""**AUTO REPLY**
\nMohon bersabar @{from_.username}, boss saya masih offline 😒"""
\nMohon bersabar @{sender.username}, boss saya masih offline 😒"""
elif senderList.count(to_.id) < 4:
message = f"""**AUTO REPLY**
\n@{from_.username} Tolong bersabar yaa 😅"""
\n@{sender.username} Tolong bersabar yaa 😅"""
else:
random_number = random.randint(0,len(quizzes) - 1)
question = quizzes[random_number]['question']
answer = quizzes[random_number]['answer']
message = f"""**AUTO REPLY**
\n @{from_.username}, Main tebak-tebakan aja yuk 😁
\n @{sender.username}, Main tebak-tebakan aja yuk 😁
\n {question}
\n {answer}
\n """
Expand Down