import tkinter as tk
from tkinter import messagebox
from instagrapi import Client
import threading
import time
# Global değişkenler
cl = None
media_ids = []
filter_words = []
response_messages = {}
check_interval = 300 # Varsayılan kontrol süresi (saniye)
is_checking = False
media_check_count = 0
response_count = 0
# Instagram hesabına bağlanma fonksiyonu
def login():
global cl
username = username_entry.get()
password = password_entry.get()
cl = Client()
try:
cl.login(username, password)
messagebox.showinfo("Başarılı", "Instagram hesabına giriş yapıldı.")
login_frame.pack_forget()
main_frame.pack()
update_status()
schedule_next_check()
except Exception as e:
messagebox.showerror("Hata", f"Giriş yapılamadı: {str(e)}")
# Yorumları kontrol etme fonksiyonu
def check_comments():
global is_checking, media_check_count, response_count
is_checking = True
for media_id in media_ids:
comments = cl.media_comments(media_id)
media_check_count += 1
for comment in comments:
for word in filter_words:
if word in comment.text.lower():
user_id = comment.user.pk
send_private_message(user_id, response_messages[word])
response_count += 1
is_checking = False
update_status()
schedule_next_check()
# Özel mesaj gönderme fonksiyonu
def send_private_message(user_id, message):
cl.direct_send(message, [user_id])
# Medya ID ekleme fonksiyonu
def add_media_id():
media_id = media_id_entry.get()
if media_id:
media_ids.append(media_id)
media_listbox.insert(tk.END, media_id)
media_id_entry.delete(0, tk.END)
messagebox.showinfo("Başarılı", "Medya ID eklendi.")
update_status()
# Medya ID kaldırma fonksiyonu
def remove_media_id():
selected_indices = media_listbox.curselection()
for index in selected_indices[::-1]:
media_ids.pop(index)
media_listbox.delete(index)
update_status()
# Filtre kelimesi ekleme fonksiyonu
def add_filter_word():
word = filter_word_entry.get()
message = response_message_entry.get()
if word and message:
filter_words.append(word)
response_messages[word] = message
filter_listbox.insert(tk.END, f"{word}: {message}")
filter_word_entry.delete(0, tk.END)
response_message_entry.delete(0, tk.END)
messagebox.showinfo("Başarılı", "Filtre kelimesi ve mesaj eklendi.")
update_status()
# Filtre kelimesi kaldırma fonksiyonu
def remove_filter_word():
selected_indices = filter_listbox.curselection()
for index in selected_indices[::-1]:
word = filter_words.pop(index)
response_messages.pop(word)
filter_listbox.delete(index)
update_status()
# Durum güncelleme fonksiyonu
def update_status():
media_count = len(media_ids)
filter_count = len(filter_words)
status_label.config(text=f"{media_count} medya, {filter_count} filtre izleniyor")
media_check_label.config(text=f"Kontrol edilen medya: {media_check_count}")
response_label.config(text=f"Yanıt verilen mesajlar: {response_count}")
# Kontrol süresini güncelleme fonksiyonu
def update_check_interval():
global check_interval
try:
check_interval = int(check_interval_entry.get())
messagebox.showinfo("Başarılı", f"Kontrol süresi {check_interval} saniye olarak ayarlandı.")
except ValueError:
messagebox.showerror("Hata", "Geçersiz kontrol süresi")
# Sonraki kontrolü zamanlama fonksiyonu
def schedule_next_check():
root.after(check_interval * 1000, check_comments)
countdown(check_interval)
# Geri sayım fonksiyonu
def countdown(time_remaining):
if time_remaining > 0:
status_label.config(text=f"Bir sonraki kontrol {time_remaining} saniye içinde")
root.after(1000, countdown, time_remaining - 1)
else:
status_label.config(text="Yorumlar kontrol ediliyor...")
# GUI oluşturma
root = tk.Tk()
root.title("Instagram Bot")
# Giriş çerçevesi
login_frame = tk.Frame(root)
tk.Label(login_frame, text="Kullanıcı Adı:").pack()
username_entry = tk.Entry(login_frame)
username_entry.pack()
tk.Label(login_frame, text="Şifre:").pack()
password_entry = tk.Entry(login_frame, show="*")
password_entry.pack()
tk.Button(login_frame, text="Giriş Yap", command=login).pack()
login_frame.pack()
# Ana çerçeve
main_frame = tk.Frame(root)
# Medya ID yönetimi
tk.Label(main_frame, text="Medya ID:").pack()
media_id_entry = tk.Entry(main_frame)
media_id_entry.pack()
tk.Button(main_frame, text="Medya ID Ekle", command=add_media_id).pack()
media_listbox = tk.Listbox(main_frame)
media_listbox.pack()
tk.Button(main_frame, text="Seçili Medya ID Kaldır", command=remove_media_id).pack()
# Filtre kelimesi ve yanıt mesajı yönetimi
tk.Label(main_frame, text="Filtre Kelimesi:").pack()
filter_word_entry = tk.Entry(main_frame)
filter_word_entry.pack()
tk.Label(main_frame, text="Yanıt Mesajı:").pack()
response_message_entry = tk.Entry(main_frame)
response_message_entry.pack()
tk.Button(main_frame, text="Filtre Kelimesi Ekle", command=add_filter_word).pack()
filter_listbox = tk.Listbox(main_frame)
filter_listbox.pack()
tk.Button(main_frame, text="Seçili Filtre Kelimesi Kaldır", command=remove_filter_word).pack()
# Kontrol süresi ayarı
tk.Label(main_frame, text="Kontrol Süresi (saniye):").pack()
check_interval_entry = tk.Entry(main_frame)
check_interval_entry.insert(0, str(check_interval))
check_interval_entry.pack()
tk.Button(main_frame, text="Kontrol Süresini Güncelle", command=update_check_interval).pack()
# Durum etiketleri
status_label = tk.Label(main_frame, text="")
status_label.pack()
media_check_label = tk.Label(main_frame, text="Kontrol edilen medya: 0")
media_check_label.pack()
response_label = tk.Label(main_frame, text="Yanıt verilen mesajlar: 0")
response_label.pack()
main_frame.pack()
root.mainloop()