Merge pull request #18 from ctx77/main

some changes
This commit is contained in:
Context 77
2025-03-04 19:12:52 +01:00
committed by GitHub
4 changed files with 16455 additions and 11296 deletions

View File

@@ -3,6 +3,8 @@ import queue
import socket
import time
import ssl
import os.path
from threading import Condition
from FaustBot.Communication.JoinObservable import JoinObservable
@@ -137,12 +139,17 @@ class Connection(object):
"""
establish the connection
"""
use_certfp = os.path.isfile("certfp.pem")
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socker = socket.create_connection(
(self.details.get_server(), self.details.get_port())
)
if self.details.get_ssl().lower() != "false":
self.wraper = ssl.create_default_context()
if use_certfp:
self.wraper = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
self.wraper.load_cert_chain("certfp.pem")
else:
self.wraper = ssl.create_default_context()
self.irc = self.wraper.wrap_socket(
socker, server_hostname=self.details.get_server()
)
@@ -152,10 +159,11 @@ class Connection(object):
self.irc.send(f"NICK {self.details.get_nick()}\r\n".encode())
self.irc.send("USER botty botty botty :Botty \n".encode())
if self.details.get_pwd() != "":
self.send_to_user(
"NICKSERV",
f"identify {self.details.get_nick()} {self.details.get_pwd()} ",
self.irc.send(
f"PRIVMSG NICKSERV :identify {self.details.get_nick()} {self.details.get_pwd()} \r\n".encode()
)
# Sleep a bit to ensure that the Bot is fully logged in.
time.sleep(11.2233)
self.irc.send(f"JOIN {self.details.get_channel()}\r\n".encode())
self.irc.send(f"WHO {self.details.get_channel()}\r\n".encode())
self.irc.send(f"MODE {self.details.get_nick()} -R\r\n".encode())

File diff suppressed because one or more lines are too long

View File

@@ -48,7 +48,7 @@ essen = [
'mildes Möhrenmischmasch','gegrillten Kürbis','knusprige Frühlingsrollen mit Dip',
'drei frische Onigiri','den Kraftriegel der deutschen Arbeiterklasse',
'Bratwurst mit Sauerkraut','ein Bündel Petersilie',
'eine Schale Stachelbeerkompott','Stulle mit Brot','einen laienhaft zubereiteten Fugofisch',
'eine Schale Stachelbeerkompott','Stulle mit Brot',
'ein Stück kichernden Käsekuchen mit Himbeeren','eine Handvoll rohe Mandeln',
'die Rechnung','entzückendes Erbsengemüse','Eierlikörkuchen mit vollständig ausgebackenem Eierlikör',
'drei Stücke traurige trockene Torte','Wassermelonensalat in einer ausgehöhlten Wassermelone',
@@ -284,5 +284,3 @@ essen = [
'einen Topf Matzah-Ball-Suppe','einen Laib geflochtenes Challah','eine XXL-Packung Merci',
'Pekingente mit Hoisin-Sauce',
]

117
nix-bot-run.sh Executable file
View File

@@ -0,0 +1,117 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash python312Packages.wikipedia python312Packages.requests
# Directory of the virtual environment
#VENV="./FaustBotVEnv"
export PYTHONDONTWRITEBYTECODE=1
venv() {
:
}
help() {
echo "Simple script to manage a single faust-bot instance."
echo " -h displays this help message"
echo " -s starts the bot, if it is not running yet"
echo " -e exits/stops the bot"
echo " -r restarts the bot"
echo " -u updates the bots code"
}
start() {
venv
echo "[=== checking if bot is already running "
if [ -f ".pid" ]; then
echo "[=== bot is already running "
echo "[=== aborting start "
else
echo "[=== bot is not running "
echo "[=== check if out.txt exists "
if [ -f "out.txt" ]; then
echo "[=== removing existing out.txt "
rm out.txt
else
echo "[=== no out.txt found "
fi
echo "[=== checking if database already exists "
if [ -f "faust_bot.db" ]; then
echo "[=== database already exists "
else
echo "[=== no database "
echo "[=== preparing database "
python ReadInternationalization.py
fi
echo "[=== starting faust-bot "
echo "[=== redirecting output to nohup.out "
nohup python -u Main.py --config config.txt >out.txt &
echo "[=== pid of bot process can be found in .pid "
echo $! >.pid
fi
}
stop() {
echo "[=== checking if bot is running "
if [ ! -f ".pid" ]; then
echo "[=== bot is not running "
else
echo "[=== bot is running "
echo "[=== killing bot process "
kill "$(cat .pid)"
echo "[=== removing .pid file "
rm .pid
fi
}
update() {
echo "[=== stopping the bot to update it "
stop
echo "[=== stashing local changes "
git stash --all
echo "[=== update the code "
git pull origin main
echo "[=== reapply done local changes "
git stash pop
echo "[=== restarting bot instance "
start
}
clean() {
echo "[=== cleaning files "
echo "[=== stopping the bot "
stop
echo "[=== removing output file "
rm out.txt
echo "[=== removing venv "
rm -rf $VENV
}
OPTIND=1
while getopts "hseruc" opt; do
case $opt in
h)
help
exit
;;
s)
start
;;
e)
stop
;;
r)
stop
start
;;
u)
update
;;
c)
clean
;;
\?)
echo "Invalid option: -$OPTARG" >&2
help
;;
esac
done