Upload 5 files
Browse filesSeveral updates
- WarBot.py +2 -2
- WarClient_old.py +18 -0
- WarOnline_Chat.py +38 -19
WarBot.py
CHANGED
@@ -85,7 +85,7 @@ def get_response(quote:str,model,tokenizer,model_punct,temperature=0.2):
|
|
85 |
user_inpit_ids = tokenizer.encode(f"|0|{get_length_param(quote, tokenizer)}|" \
|
86 |
+ quote + tokenizer.eos_token, return_tensors="pt")
|
87 |
except:
|
88 |
-
return "" # Exception in tokenization
|
89 |
|
90 |
chat_history_ids = user_inpit_ids # To be changed
|
91 |
|
@@ -110,7 +110,7 @@ def get_response(quote:str,model,tokenizer,model_punct,temperature=0.2):
|
|
110 |
#device='cpu'
|
111 |
)
|
112 |
except:
|
113 |
-
return "" # Exception in generation
|
114 |
|
115 |
response = tokenizer.decode(output_id[0], skip_special_tokens=True)
|
116 |
response = removeSigns(response)
|
|
|
85 |
user_inpit_ids = tokenizer.encode(f"|0|{get_length_param(quote, tokenizer)}|" \
|
86 |
+ quote + tokenizer.eos_token, return_tensors="pt")
|
87 |
except:
|
88 |
+
return "Exception in tokenization" # Exception in tokenization
|
89 |
|
90 |
chat_history_ids = user_inpit_ids # To be changed
|
91 |
|
|
|
110 |
#device='cpu'
|
111 |
)
|
112 |
except:
|
113 |
+
return "Exception" # Exception in generation
|
114 |
|
115 |
response = tokenizer.decode(output_id[0], skip_special_tokens=True)
|
116 |
response = removeSigns(response)
|
WarClient_old.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import socket
|
2 |
+
|
3 |
+
HOST = '129.159.146.88'
|
4 |
+
PORT = 5000
|
5 |
+
|
6 |
+
#message = "Если посмотреть на небо, можно увидеть как улетает башня от Т-72"
|
7 |
+
#message = "Тестовый бот WarOnline - доложить о работоспособности систем!"
|
8 |
+
|
9 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
|
10 |
+
client_socket.connect((HOST, PORT))
|
11 |
+
client_socket.sendall(message.encode())
|
12 |
+
print('Wait...')
|
13 |
+
data = client_socket.recv(1024)
|
14 |
+
try:
|
15 |
+
received_string = data.decode('utf-8')
|
16 |
+
print(f'Received string from server: {received_string}')
|
17 |
+
except: #sometimes there is a problem with the decoding
|
18 |
+
print('decoding error, please try again')
|
WarOnline_Chat.py
CHANGED
@@ -8,6 +8,7 @@ import urllib.request as urllib
|
|
8 |
import warnings
|
9 |
import schedule
|
10 |
import time
|
|
|
11 |
warnings.filterwarnings("ignore")
|
12 |
|
13 |
# Define the login URL and the thread URL
|
@@ -110,8 +111,7 @@ def allQuotesFor(thread_url=thread_url, username=username, startingPage=1):
|
|
110 |
response = requests.get(thread_url + 'page-' + str(page))
|
111 |
if response.status_code == 200:
|
112 |
|
113 |
-
#
|
114 |
-
response = session.get(thread_url)
|
115 |
html_content = response.content
|
116 |
|
117 |
# Parse the HTML content using BeautifulSoup
|
@@ -133,8 +133,13 @@ def allQuotesFor(thread_url=thread_url, username=username, startingPage=1):
|
|
133 |
if matchID:
|
134 |
messageID = matchID.group(1)
|
135 |
|
136 |
-
|
|
|
|
|
|
|
|
|
137 |
allquotes.append({'reply': reply, 'messengerName': messengerName, 'messageID': messageID})
|
|
|
138 |
except:
|
139 |
continue # There was no text in quote, move next
|
140 |
|
@@ -151,28 +156,42 @@ def allQuotesFor(thread_url=thread_url, username=username, startingPage=1):
|
|
151 |
def WarOnlineBot():
|
152 |
# Get All Quotes
|
153 |
quotes = allQuotesFor(thread_url=thread_url, username=username, startingPage=1)
|
154 |
-
|
155 |
-
# Search for quotes withou the relpy and answer them
|
156 |
for quote in quotes:
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
print('Quote: ', quote['reply'])
|
160 |
-
print(
|
|
|
|
|
|
|
|
|
161 |
|
162 |
|
163 |
if __name__ == '__main__':
|
164 |
-
timeout =
|
165 |
-
login(username=username, password=password, thread_url=thread_url)
|
166 |
-
|
167 |
#post(message=message, thread_url=thread_url, post_url=post_url,quoted_by='Василий Пупкин',quote_text='Testing the XenForo response mechanism')
|
168 |
|
169 |
-
# Set up schedule function
|
170 |
-
schedule.every(timeout).minutes.do(WarOnlineBot)
|
171 |
-
|
172 |
# Start the scheduler
|
173 |
while True:
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
8 |
import warnings
|
9 |
import schedule
|
10 |
import time
|
11 |
+
from tqdm import tqdm
|
12 |
warnings.filterwarnings("ignore")
|
13 |
|
14 |
# Define the login URL and the thread URL
|
|
|
111 |
response = requests.get(thread_url + 'page-' + str(page))
|
112 |
if response.status_code == 200:
|
113 |
|
114 |
+
# Core of the function
|
|
|
115 |
html_content = response.content
|
116 |
|
117 |
# Parse the HTML content using BeautifulSoup
|
|
|
133 |
if matchID:
|
134 |
messageID = matchID.group(1)
|
135 |
|
136 |
+
if 'Click' in data.text:
|
137 |
+
reply = data.text.split("Click to expand...")[-1].replace('\n', ' ').strip()
|
138 |
+
elif "Нажмите" in data.text:
|
139 |
+
reply = data.text.split("Нажмите для раскрытия...")[-1].replace('\n', ' ').strip()
|
140 |
+
|
141 |
allquotes.append({'reply': reply, 'messengerName': messengerName, 'messageID': messageID})
|
142 |
+
|
143 |
except:
|
144 |
continue # There was no text in quote, move next
|
145 |
|
|
|
156 |
def WarOnlineBot():
|
157 |
# Get All Quotes
|
158 |
quotes = allQuotesFor(thread_url=thread_url, username=username, startingPage=1)
|
159 |
+
repliedMessageIDs = []
|
|
|
160 |
for quote in quotes:
|
161 |
+
replies = allQuotesFor(thread_url=thread_url, username=quote['messengerName'], startingPage=1)
|
162 |
+
for reply in replies: # Remove all non-relevant and previously answered replies
|
163 |
+
|
164 |
+
if reply['messengerName']!=username or reply['messageID'] in repliedMessageIDs:
|
165 |
+
replies.remove(reply)
|
166 |
+
else:
|
167 |
+
repliedMessageIDs.append(reply['messageID'])
|
168 |
+
repliedMessageIDs = list(set(repliedMessageIDs))
|
169 |
+
# There is still some strange error. Will take a look later
|
170 |
+
|
171 |
+
message = ""
|
172 |
+
if not replies: # Meaning that there are no answers
|
173 |
+
while not message:
|
174 |
+
message = WarClient.getReply(message=quote['reply'])
|
175 |
print('Quote: ', quote['reply'])
|
176 |
+
print('Reply: ',message)
|
177 |
+
post(message=message, thread_url=thread_url, post_url=post_url, quoted_by=quote['messengerName'],
|
178 |
+
quote_text=quote['reply'])
|
179 |
+
print('posted the message to the forum')
|
180 |
+
time.sleep(5) # Standby time for server load release
|
181 |
|
182 |
|
183 |
if __name__ == '__main__':
|
184 |
+
timeout = 2 # min
|
|
|
|
|
185 |
#post(message=message, thread_url=thread_url, post_url=post_url,quoted_by='Василий Пупкин',quote_text='Testing the XenForo response mechanism')
|
186 |
|
|
|
|
|
|
|
187 |
# Start the scheduler
|
188 |
while True:
|
189 |
+
login(username=username, password=password, thread_url=thread_url)
|
190 |
+
print("logged in")
|
191 |
+
WarOnlineBot()
|
192 |
+
p_bar = tqdm(range(60 * timeout))
|
193 |
+
|
194 |
+
for i in p_bar:
|
195 |
+
p_bar.update(1)
|
196 |
+
p_bar.refresh()
|
197 |
+
time.sleep(1)
|