Untitled
unknown
plain_text
2 years ago
1.7 kB
17
Indexable
from BotAmino import BotAmino
import json
from threading import Thread
file = "old_messages.json"
client = BotAmino("joiau46@gmail.com", "666666")
# Load old messages from file
def load_old_messages():
try:
with open(file, "r") as f:
return json.load(f)
except Exception:
return {}
# Save messages to file
def save_message(chat_id, message_id, message_content, author_icon, author_id, author_name):
old_messages = load_old_messages()
if chat_id not in old_messages:
old_messages[chat_id] = {}
old_messages[chat_id][message_id] = {
"message": message_content,
"authorIcon": author_icon,
"authorId": author_id,
"author": author_name
}
with open(file, "w") as f:
json.dump(old_messages, f, indent=4)
# Assume we have the bot's author ID
bot_author_id = "your_bot_author_id_here"
@client.on_message()
def handle_message(data):
if data.chatId != "c5617a7f-9089-4703-bc39-19e0200aaf29":
return
# Check if the message is from the bot itself; if so, do not save it.
if data.authorId == bot_author_id:
return
save_message(
data.chatId,
data.messageId,
data.message,
data.authorIcon,
data.authorId,
data.author
)
@client.command("send_message")
def terminal_inputs():
comId = 132142553
chatId = 'c5617a7f-9089-4703-bc39-19e0200aaf29'
while True:
msg = input(">>> ").strip()
if comId not in client.communaute:
print('community not launched')
continue
bot = client.get_community(comId)
bot.send_message(chatId, message=msg)
Thread(target=terminal_inputs).start()
client.launch()
print("ready")Editor is loading...
Leave a Comment