import pytz
import tools.smart_privmsg
from aptbot.bot import Bot, Commands, Message
-from scripts.subathon import sock
+from scripts.subathon import send
PERMISSION = 10
PREFIX = "\\"
data = {
"set_ts": ts,
}
- sock.send(json.dumps(data).encode())
+ send(data)
def add_time(ts: int):
data = {
"add_ts": ts,
}
- sock.send(json.dumps(data).encode())
+ send(data)
def now():
data = {
- "set_ts": datetime.now(pytz.UTC),
+ "set_ts": int(datetime.timestamp(datetime.now(pytz.UTC))),
}
- sock.send(json.dumps(data).encode())
+ send(data)
def main(bot: Bot, message: Message):
if message.command == Commands.PRIVMSG:
if message.nick == "skgyorugo":
- if message.value == "\\test":
- message = tools.test_message.test()
+ if message.value.startswith("\\test"):
+ message = tools.test_message.test(*message.value.split(" ")[1:])
+ scripts.subathon.subathon(bot, message)
+ return
if message.command == Commands.PRIVMSG:
database_manager.add_message_to_chat_history(message)
if message.value[0] in {"?", "\\"}:
import os
import socket
import sqlite3
+import time
import socketio
import tools.smart_privmsg
if bits := message.tags.get("bits"):
# Every 400 bits is the same as a sub,
# assuming you already subbed 10 times
- div_count = (int(bits) // 400) * calculate_increase(10)
+ div_count = (int(bits) // 400) * calculate_increase(5)
# Add 3 seconds for every 1 bit under 400 bits
rest_count = (int(bits) % 400) * 3
"time": total_timer,
"name": display_name,
}
- sock.send(json.dumps(data).encode())
+ send(data)
verb = "INCREASED ihaspeHappy" if total_timer > 0 else "DECREASED ihaspeAngi"
msg = (
def event(data):
if data["type"] == "donation":
amount_cents = int(float(data["message"][0]["amount"]) * 100)
- div_count = (amount_cents // 400) * calculate_increase(10)
+ div_count = (amount_cents // 400) * calculate_increase(5)
# Add 3 seconds for every 1 cent under 400 cents
- rest_count = (amount_cents % 400) * 3
+ rest_count = (amount_cents % 400) * 4
timer_add = div_count + rest_count
display_name = data["message"][0]["from"]
"time": total_timer,
"name": display_name,
}
- sock.send(json.dumps(data).encode())
+ send(data)
logger.info("%s donated %s", display_name, amount_cents)
verb = (
def calculate_increase(sub_count: int) -> int:
- scale = 0.006
+ scale = 0.01
avg_time = ceil(30.0 * exp(-scale * sub_count) + 5.0)
- var_time = 35.0 / (1 + exp(-0.15 * (sub_count - 10))) - 5.0
+ var_time = 35.0 / (1 + exp(-0.3 * (sub_count - 11)))
return ceil(normal(avg_time, var_time) * 60.0)
+def send(data: dict) -> None:
+ global sock
+ try:
+ sock.send(json.dumps(data).encode())
+ except (BrokenPipeError, OSError) as e:
+ logger.exception(e)
+ close()
+ time.sleep(1)
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ start()
+ sock.send(json.dumps(data).encode())
+
+
def start() -> None:
sock.connect(socket_file)
def test(test_type: str, sub_type: str) -> Message:
- text_path = os.path.join(PATH, "messages", test_type, sub_type + ".txt")
+ text_path = os.path.join(TOOLS_PATH, "messages", test_type, sub_type + ".txt")
f = open(text_path, "w")
message = random.choice(f.readlines())
f.close()