def start(bot: Bot, message: Message, stop_event: Event):
i = 0
wait = 5
+ scripts.subathon.start()
scripts.subathon.donations(bot, message)
while not stop_event.is_set():
i += wait
analyze_auto_message.do_auto_message(bot, message, auto_message_modules)
i = 0
time.sleep(wait)
+ scripts.subathon.close()
def main(bot: Bot, message: Message):
import socketio
import tools.smart_privmsg
from aptbot.bot import Bot, Commands, Message
-from numpy import array, ceil, exp, sum
+from numpy import ceil, exp
from numpy.random import normal
logger = logging.getLogger(__name__)
SCRIPTS_PATH = os.path.dirname(os.path.realpath(__file__))
PATH = os.path.join(SCRIPTS_PATH, "..")
-socket_file = os.getenv("SUBATHON_SOCKET", "~/.cache/subathon.sock")
+socket_file = os.getenv("SUBATHON_SOCKET", "/tmp/subathon.sock")
conn = sqlite3.connect(os.path.join(PATH, "subathon.db"))
c = conn.cursor()
conn.commit()
c.close()
+sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+
def subathon(bot: Bot, message: Message):
if message.command == Commands.USERNOTICE:
return
total_timer = timer_add * multiplier
- with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
- client.connect(socket_file)
- data = {
- "time": total_timer,
- "name": display_name,
- }
- client.send(json.dumps(data).encode())
- client.close()
+ data = {
+ "time": total_timer,
+ "name": display_name,
+ }
+ sock.send(json.dumps(data).encode())
verb = "INCREASED ihaspeHappy" if total_timer > 0 else "DECREASED ihaspeAngi"
msg = (
@io.on("event")
def event(data):
- if data["type"] == "donations":
+ if data["type"] == "donation":
amount_cents = int(float(data["message"][0]["amount"]) * 100)
div_count = (amount_cents // 400) * calculate_increase(10)
display_name = data["message"][0]["from"]
total_timer = timer_add
- with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
- client.connect(socket_file)
- data = {
- "time": total_timer,
- "name": display_name,
- }
- client.send(json.dumps(data).encode())
- client.close()
+ data = {
+ "time": total_timer,
+ "name": display_name,
+ }
+ sock.send(json.dumps(data).encode())
logger.info("%s donated %s", display_name, amount_cents)
verb = (
avg_time = ceil(30.0 * exp(-scale * sub_count) + 5.0)
var_time = 35.0 / (1 + exp(-0.15 * (sub_count - 10))) - 5.0
return ceil(normal(avg_time, var_time) * 60.0)
+
+
+def start() -> None:
+ sock.connect(socket_file)
+
+
+def close() -> None:
+ sock.close()