- This topic has 14 replies, 5 voices, and was last updated 1 day ago by
musicbot2023.
-
AuthorPosts
-
April 1, 2023 at 12:17 am #209412
VN
MemberThis topic was created to help programmers, solve problems in creating bots for new paltalk.
Please describe the errors you have encountered, and what you want to be created in the next version of paltalk.
Download beta version, 1.29.89332: https://downloads.paltalk.com/download/beta/PaltalkSetup.exeThe answer from the paltalk development team:
>1. I need some way of sending text into the room. I can place text into “ui::controls::EmojiTextEdit”, but I don’t see >any way of sending that text into the room other than to send a newline character to the entire Paltalk application, >which isn’t ideal. Perhaps the “Invoke” of that automation element could send the line into the room.
This can be done using Win API on our latest build 1.29.0.89332.
1. Find “DlgGroupChat Window Class” window handler, FindWindowW can be used.
2. Find “RichEdit20W” window handler in the children list. EnumChildWindows can be used.
3. Send WM_SETTEXT message using SendMessage function to send a message to the room.>2. I need some way of reading who is on mic. Nowhere in the Talking Now/Mic Queue/Chatting column of users does it show >the name of the user, for example not shown in “ui::widgets::UsernameWidget”
This also can be done using Win API on our latest build 1.29.0.89332.
1. Find “DlgGroupChat Window Class” window handler, FindWindowW can be used.
2. Find “SysHeader32” window handler in the children list. EnumChildWindows can be used.
3. Send LVM_GETITEMCOUNT message using SendMessage function to get room users count.
4. Send LVM_GETITEMW message with the LVITEMW pointer for the each user index using SendMessage function to get room member mic status. LVITEMW::iImage will contains 10 if the mic is on.
5. Send LVM_GETITEMTEXTA message for the each user index using SendMessage function to get room member nickname.>3. emoji support. This is relatively minor, but limiting. Some emoji don’t show up in UI Automation elements. For >example, I can enter into the room and it won’t show up in QTextBrowser. QTextBrowser says there is a character >there, but it won’t show it and it isn’t in the text that I grab from that automation element.
We’ll try to resolve this issue in the future.
+ Please comment and see if this is useful or not
April 1, 2023 at 3:36 am #209447chicagodavid52
MemberThanks, elsewhere I said I had problems with the steps above, but I didn’t use the full name of “DlgGroupChat Window Class” when searching for the window. I’ll try those items…
I went through a lot of work to read the content of the room correctly and my code gets confused if the user ever scrolls the room backwards. I see the dev team seems to be using WIndows controls now for content to help those writing bots. I do believe it would be easier for others writing bots to read the room if it worked like it did in Classic, i.e., a bot pulling a line at a time from a rich text box and every line preceded by the nic as what happens when one copies and pastes content from a room. So I’ll put that out there for others to comment.April 1, 2023 at 5:08 am #209462VN
MemberThanks for your feedback. paltalk development team is always ready to help you and always listen to your opinion to provide a better timely solution.
April 1, 2023 at 1:56 pm #209566chicagodavid52
MemberI can’t get item 1 to work. I find 2 handles but when I do a wm_settext it only prints out the first letter in the string into the Paltalk room. Also if there is a unicode as the first letter it prints out garbage even though SendMessage is set for unicode.
Dim roomName As String
roomName = ReadRoomForm.cbxRoomName.Text
Dim hndl As IntPtr = FindWindow(“DlgGroupChat Window Class”, roomName)
If hndl = IntPtr.Zero Then
Exit Sub
End If
Dim editHndl As IntPtr
editHndl = FindWindowByClass(hndl, “RichEdit20W”)
If editHndl = IntPtr.Zero Then
Exit Sub
End If
SendMessage(editHndl, WM_SETTEXT, IntPtr.Zero, Line)
PostMessage(editHndl, WM_KEYDOWN, RETURNKEY, IntPtr.Zero) ‘send RETURN key.April 2, 2023 at 2:57 pm #209807chicagodavid52
MemberI couldn’t get item 2 to work either. I was using LVM_GETITEMW but since Paltalk is in a different process I have to allocate memory in the Paltalk process to read it,e.g. VirtualAllocEx, and then I have to copy that memory to my process. Anyway, I tested it on a list view in one of my programs and it worked by returning the list of items, but with Paltalk I got empty strings.
Oh, and eventually I’d like to read who is in Queue (and their order) and I’m not sure how getting a list of users in the room would tell me that.
Another desired feature would be to easily dot the person on mic, and then immediately undot them. This is for users who overstay their time on mic. Dotting them on mic in the current Paltalk isn’t too difficult, but undotting is difficult because dotted users immediately drop to the bottom of the user list. In a large room that means scrolling to the bottom. Some bots in Classic were written to get to a user by using keystroke scrolling built into Windows controls (i.e. typing the first few characters in the name gets you to the name in the list). There is no such ability in this Paltalk client.
Considering how difficult this is I don’t know why the UI Automation structure is not expanded a little to list the user nickname. That would be easier for me.
April 8, 2023 at 5:07 pm #211073VN
MemberThanks ChicagoDavid52 – we’ll take a look at this, right now we’re going to limit the scope to make existing bots work, so some of these new features may come later or in a new way some time in the future.
April 9, 2023 at 2:23 am #211215linker
MemberPaltalk needs to make a version for Linux and I think for click and install like a windows exe file for Linux it should be a “.deb” files. With the likes of gnome 44 it’s getting so easy to use Linux.
A friend of mine his mother is in her late 70’s was having trouble with Windows and was calling him up 3 to 4 times a week with problems. so he decided to install ZorinOZ on her system he said now she might call him twice a week. Most things you see on youtube like the terminal is not needed for the average person there just tinkers who want to learn to be more advanced.
Also the end of life for Windows 10 is coming on fast and a alternative for paltalk would be nice. My computer supports Windows 11 so I’m speaking for others who can’t get windows 11 and Linux is so much fun to use.
May 10, 2023 at 10:48 am #213152spid3r
Memberhello guys, i try to write bot for paltalk with chatgpt incorporated. I have a problem with bot when it has to type in room. It seems it cant recognize list user and room name.
here my coode :
import openai
import time
import pywinauto
import win32gui
import win32api
import win32con
from pywinauto import Application
import keyboard
import pygetwindow as gw
import psutil# Add these lines after the imports section
LVM_GETITEMCOUNT = 0x1000
LVM_GETITEMW = 0x104B
LVM_GETITEMTEXTA = 0x1045
CHAT_ROOM_NAME = “INSERT ROOM NAME”
PALTALK_WINDOW_CLASS = “Paltalk Messenger Window Class”# Replace with your Paltalk username
PAL_USERNAME = “INSERT YOUR NICK BOT”# Replace with your OpenAI API keys
openai.api_key = “INSERT YOUR CHATGPT API”# The conversation prompt to start a conversation with the OpenAI API
conversation_prompt = (“The following is a conversation with an AI assistant. ”
“The assistant is helpful, creative, clever, and very friendly.”
“User: Hello, who are you?”)# The maximum number of messages the bot can send in a row
max_num_responses = 3# The amount of time (in seconds) to wait before sending another message
delay_between_responses = 2def find_chat_window():
chat_window = win32gui.FindWindow(“DlgGroupChat Window Class”, None)
print(f”Chat window: {chat_window}”) # Add this line
return chat_windowdef find_chat_input(chat_window):
def callback(hwnd, hwnds):
if win32gui.GetClassName(hwnd) == “RichEdit20W”:
hwnds.append(hwnd)
return Truehwnds = []
win32gui.EnumChildWindows(chat_window, callback, hwnds)
chat_input = hwnds[0] if hwnds else None
print(f”Chat input: {chat_input}”) # Add this line
return chat_inputdef find_chat_input(chat_window):
def callback(hwnd, hwnds):
if win32gui.GetClassName(hwnd) == “RichEdit20W”:
hwnds.append(hwnd)
return Truehwnds = []
win32gui.EnumChildWindows(chat_window, callback, hwnds)
return hwnds[0] if hwnds else Nonedef get_main_window_handle(app_name):
app_windows = pywinauto.findwindows.find_elements(title_re=app_name, backend=’uia’)
if app_windows:
return app_windows[0].handle
return Nonedef get_user_count(chat_window):
sysheader = None
def callback(hwnd, hwnds):
nonlocal sysheader
if win32gui.GetClassName(hwnd) == “SysHeader32”:
sysheader = hwnd
return Truewin32gui.EnumChildWindows(chat_window, callback, [])
return win32api.SendMessage(sysheader, LVM_GETITEMCOUNT, 0, 0)def get_user_info(chat_window, index):
sysheader = None
def callback(hwnd, hwnds):
nonlocal sysheader
if win32gui.GetClassName(hwnd) == “SysHeader32”:
sysheader = hwnd
return Truewin32gui.EnumChildWindows(chat_window, callback, [])
lvitem = win32api.SendMessage(sysheader, LVM_GETITEMW, index, 0)
user_on_mic = lvitem.iImage == 10
user_nickname = win32api.SendMessage(sysheader, LVM_GETITEMTEXTA, index, 0)return user_on_mic, user_nickname
def send_message(chat_window, message):
# Remove logic to restart Paltalkchat_window_title = CHAT_ROOM_NAME
chat_windows = gw.getWindowsWithTitle(chat_window_title)chat_window = None
for window in chat_windows:
if window.isActive:
chat_window = window
break# Check if Paltalk process is running before assuming it’s closed
for process in psutil.process_iter():
if “Paltalk.exe” in process.name():
is_running = True
break
else:
is_running = Falseif not is_running:
print(“Paltalk does appear to actually be closed.”)
returnif chat_window is None:
print(“Unable to find Paltalk chat window.”)
return# Use the PyGetWindow window object
chat_window.activate()
chat_window.restore()# Default to searching for “Paltalk Messenger Window” if title search fails
if not chat_window and not chat_windows:
chat_window = gw.getWindowsWithTitle(“Paltalk Messenger Window”)[0]if not chat_window:
print(“Paltalk does not appear to be open. Restarting…”)
# Add logic to restart Paltalk…
return# Use the window object’s methods
chat_window.activate()
chat_window.restore()# ACTIVE CHAT WINDOW IS chat_window – NO active_chat VARIABLE NEEDED
chat_window.activate()
chat_window.restore()# Use .activate() and .restore() as a fallback if SetForegroundWindow doesn’t work
active_chat.activate()
active_chat.restore()# Increase sleep time
while win32gui.GetForegroundWindow() != chat_window:
print(f”Foreground window: {win32gui.GetForegroundWindow()}, chat window: {chat_window}”)
time.sleep(0.5) # Increased from 0.1chat_window_gw = chat_windows[0]
# Ensure the chat window is visible and focused
print(“Restoring and activating the chat window…”)
chat_window_gw.restore()
chat_window_gw.activate()# Fallback: use SetForegroundWindow if the chat window is still not in the foreground
if win32gui.GetForegroundWindow() != chat_window:
print(“Using SetForegroundWindow as a fallback…”)
win32gui.SetForegroundWindow(chat_window)# Wait for the window to be active
print(“Waiting for the chat window to be in the foreground…”)
while win32gui.GetForegroundWindow() != chat_window:
print(f”Foreground window: {win32gui.GetForegroundWindow()}, chat window: {chat_window}”)
time.sleep(0.1)# Send the message
print(“Sending the message…”)
time.sleep(0.5) # Add this line to introduce a delay before sending the message
keyboard.write(message)
keyboard.press(“enter”)
keyboard.release(“enter”)
print(“Message sent.”)# Try different combinations of titles and window classes
titles = [CHAT_ROOM_NAME, “untitled – Chat Window”]
classes = [PALTALK_WINDOW_CLASS, “Paltalk Chat Window Class”]
for title in titles:
for window_class in classes:
# Search by title and class
chat_window = win32gui.FindWindow(window_class, title)
if chat_window:
break# If still not found, just search by title
if not chat_window:
chat_window = gw.getWindowsWithTitle(title)if chat_window:
break# Very broad searches as a last resort
if not chat_window:
chat_window = win32gui.FindWindow(None, “*Paltalk*”)# Additional error handling
if not chat_window:
print(“Unable to find the Paltalk chat window. Retrying…”)
time.sleep(5) # Retry after 5 seconds
send_message(chat_window, message)def generate_response(message):
response = openai.Completion.create(
engine=”davinci”,
prompt=f”{conversation_prompt} User: {message}”,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)response_text = response.choices[0].text.strip()
return response_textdef main():
print(“Bot is running…”)
chat_window = find_chat_window()
if not chat_window:
print(“Couldn’t find the chat window”)
returnjoined_rooms = [“INSERT ROOM NAME”, ]
for room in joined_rooms:
send_message(chat_window, f”Hello everyone, I’ve just joined the room {room}!”)while True:
user_count = get_user_count(chat_window)
for i in range(user_count):
user_on_mic, user_nickname = get_user_info(chat_window, i)
if user_on_mic:
print(f”{user_nickname} is on the mic”)time.sleep(10)
if __name__ == “__main__”:
main()iF someone wanna help me about this code it will be appreciate. I tried a lot of library for def send message but nothing…
May 12, 2023 at 10:50 am #213154spid3r
Memberok now bot find room, problem still send text in room 😐
May 22, 2023 at 10:19 pm #213162VN
MemberHello spid3r. What is your paltalk nickname?
May 23, 2023 at 6:02 pm #213163VN
MemberTo spid3r: ( problem still send text in room )
Hi bro… Because there was no formatting to the code it was hard to understands it’s intent. but our development team came up with a snippet on how to send a message that you can pass alongimport win32gui, win32con hwnd_send = 0 room_list = [] def init_room_list_cb(hwnd, lparam): name = win32gui.GetClassName(hwnd) if name == "DlgGroupChat Window Class": global room_list room_list.append(win32gui.GetWindowText(hwnd)) def init_room_list(): win32gui.EnumWindows(init_room_list_cb, 0) if not room_list: print("No rooms found") def dlg_group_chat_cb(hwnd, lparam): name = win32gui.GetClassName(hwnd) global hwnd_send if name == "RichEdit20W": hwnd_send = hwnd def init_room_hwnd(room_name): window = win32gui.FindWindow("DlgGroupChat Window Class", room_name) win32gui.EnumChildWindows(window, dlg_group_chat_cb, 0) def send_text(text): win32gui.SendMessage(hwnd_send, win32con.WM_SETTEXT, 0, text.encode('ascii')) if __name__ == '__main__': init_room_list() print("Rooms:", room_list) init_room_hwnd(room_list[0]) send_text("Connected to the room: " + room_list[0])
download file : paltalk_bot_example.py
https://drive.google.com/file/d/1wy5E9zgehrwQcjYh1dZaZDDtZxfNXRG0/view?usp=share_linkMay 23, 2023 at 6:03 pm #213164VN
Memberdownload file : paltalk_bot_example.py
https://drive.google.com/file/d/1wy5E9zgehrwQcjYh1dZaZDDtZxfNXRG0/view?usp=share_linkMay 24, 2023 at 9:10 am #213165VN
MemberEveryone can come here to chat
https://groups.google.com/g/developerpaltalkMay 30, 2023 at 3:28 pm #213169spid3r
MemberIt work !!!! thanks a lot
May 31, 2023 at 5:08 am #213170 -
AuthorPosts
Related
- You must be logged in to reply to this topic.