Files
overub/modules/automation/__init__.py
2025-12-21 17:12:32 +01:00

119 lines
4.1 KiB
Python

import asyncio
from core.module import Module
class AutomationModule(Module):
name = "automation"
version = "0.1.0"
description = "Automation commands"
async def on_load(self) -> None:
builder = self.commands
self._autoreply_enabled = False
self._autoreply_text = ""
self._afk_enabled = False
self._afk_reason = ""
self._forward_enabled = False
self._forward_target = None
async def on_message(evt):
if not self._autoreply_enabled:
return
message = evt.payload.get("message")
event = evt.payload.get("event")
if getattr(event, "out", False):
return
if message and hasattr(message, "reply"):
await message.reply(self._autoreply_text)
if self._afk_enabled and message and hasattr(message, "reply"):
await message.reply(f"AFK: {self._afk_reason}")
if self._forward_enabled and message and self._forward_target:
try:
await event.client.forward_messages(self._forward_target, message)
except Exception:
self.log.exception("Auto-forward failed")
self.app.events.on("on_message_new", on_message)
@builder.command(
name="afk",
description="Stub AFK",
category="automation",
usage=".afk <reason>",
)
async def afk_cmd(event, args):
if args:
self._afk_enabled = True
self._afk_reason = " ".join(args)
await event.reply("AFK enabled")
else:
self._afk_enabled = False
self._afk_reason = ""
await event.reply("AFK disabled")
@builder.command(
name="schedule",
description="Schedule a message in seconds",
category="automation",
usage=".schedule <seconds> <text>",
)
async def schedule_cmd(event, args):
if len(args) < 2:
await event.reply("Usage: .schedule <seconds> <text>")
return
try:
seconds = int(args[0])
except ValueError:
await event.reply("Invalid seconds")
return
text = " ".join(args[1:])
await event.reply(f"Scheduled in {seconds}s")
await asyncio.sleep(seconds)
await event.reply(text)
@builder.command(
name="autoreply",
description="Toggle auto-reply",
category="automation",
usage=".autoreply <on|off> [text]",
)
async def autoreply_cmd(event, args):
if not args:
await event.reply("Usage: .autoreply <on|off> [text]")
return
if args[0] == "on":
self._autoreply_enabled = True
self._autoreply_text = " ".join(args[1:]) or "Auto-reply enabled"
await event.reply("Auto-reply enabled")
return
if args[0] == "off":
self._autoreply_enabled = False
await event.reply("Auto-reply disabled")
return
await event.reply("Usage: .autoreply <on|off> [text]")
@builder.command(
name="autoforward",
description="Stub auto-forward",
category="automation",
usage=".autoforward",
)
async def autoforward_cmd(event, args):
if not args:
await event.reply("Usage: .autoforward <on|off> <chat_id>")
return
if args[0] == "on" and len(args) > 1:
self._forward_enabled = True
self._forward_target = int(args[1])
await event.reply("Auto-forward enabled")
return
if args[0] == "off":
self._forward_enabled = False
self._forward_target = None
await event.reply("Auto-forward disabled")
return
await event.reply("Usage: .autoforward <on|off> <chat_id>")