async def __(msg, ctx): # Image with open(get_path(__file__, "assets/pizza.png"), "rb") as fh: image = Attachment.new(fh.read(), "pizza.png") await ctx.reply(t("Image"), attachments=image) # Document with open(get_path(__file__, "assets/pizza.png"), "rb") as fh: doc = Attachment.new(fh.read(), "pizza.png") await ctx.reply(t("Document"), attachments=doc) # Audio message with open(get_path(__file__, "assets/audio.ogg"), "rb") as fh: audio_message = Attachment.new(fh.read(), "audio.ogg", "voice") await ctx.reply(t("Audio message"), attachments=audio_message)
async def __(msg, ctx): if ctx.sender["state"] == WAITING: await ctx.sender.update({"state": ""}, remove=['waited_since']) await ctx.reply(t("Now I forgot you!")) else: await ctx.reply(t("Who are you?"))
async def __(msg, ctx): waited_for = int(time.time() - ctx.sender["waited_since"]) await ctx.reply( t("I'm already waiting for {} seconds!", waited_for, num=waited_for))
async def __(msg, ctx): await ctx.sender.update({"state": WAITING, "waited_since": time.time()}) await ctx.reply(t("Now I'm waiting!"))
import time from kutana import Plugin, t plugin = Plugin( t("Waiter"), description=t("Waits for you if you ask it to (.wait, .forget)")) WAITING = "waiter:waiting" @plugin.on_commands(["wait"]) @plugin.expect_sender(state="") async def __(msg, ctx): await ctx.sender.update({"state": WAITING, "waited_since": time.time()}) await ctx.reply(t("Now I'm waiting!")) @plugin.on_commands(["wait"]) @plugin.expect_sender(state=WAITING) async def __(msg, ctx): waited_for = int(time.time() - ctx.sender["waited_since"]) await ctx.reply( t("I'm already waiting for {} seconds!", waited_for, num=waited_for)) @plugin.on_commands(["forget"]) @plugin.expect_sender() async def __(msg, ctx): if ctx.sender["state"] == WAITING: await ctx.sender.update({"state": ""}, remove=['waited_since']) await ctx.reply(t("Now I forgot you!"))
from kutana import Plugin, t from utils.database import Database plugin = Plugin(name=t("UserDialog")) cursor = Database.cursor() @plugin.on_commands(["start"]) async def __(msg, ctx): cursor.execute("SELECT user FROM query WHERE user = ?", [msg.sender_id]) user = cursor.fetchone() if not user: cursor.execute("INSERT INTO query VALUES(?,NULL)", [msg.sender_id]) Database.commit() await ctx.reply("Вы скоро будете подключены к собеседнику") else: await ctx.reply("Вы уже стоите в очереди")
from kutana import Plugin, t from utils.database import Database plugin = Plugin(name=t("MessageRedirect")) cursor = Database.cursor() @plugin.on_unprocessed_messages() async def __(msg, ctx): cursor.execute("SELECT user, helper FROM query WHERE user = ? OR helper = ?", [msg.sender_id, msg.sender_id]) result = cursor.fetchone() if not result: await ctx.reply("Начните диалог, отправив команду /start") return opponent = [e for e in result if e != msg.sender_id] opponent_id = opponent[0] await ctx.send_message(opponent_id, "Собеседник: " + msg.text, attachments=msg.attachments)
from kutana import Plugin, Attachment, get_path, t plugin = Plugin(name=t("Attachments"), description=t("Sends some attachments (.attachments)")) @plugin.on_commands(["attachments"]) async def __(msg, ctx): # Image with open(get_path(__file__, "assets/pizza.png"), "rb") as fh: image = Attachment.new(fh.read(), "pizza.png") await ctx.reply(t("Image"), attachments=image) # Document with open(get_path(__file__, "assets/pizza.png"), "rb") as fh: doc = Attachment.new(fh.read(), "pizza.png") await ctx.reply(t("Document"), attachments=doc) # Audio message with open(get_path(__file__, "assets/audio.ogg"), "rb") as fh: audio_message = Attachment.new(fh.read(), "audio.ogg", "voice") await ctx.reply(t("Audio message"), attachments=audio_message)
async def __(msg, ctx): await ctx.reply(t("Plugins") + ":\n" + "\n".join( "- {} - {}".format(pl.name, pl.description) for pl in plugin.plugins ))
from kutana import Plugin, t plugin = Plugin( name=t("Plugins"), description=t("Sends installed plugins (.plugins)"), plugins=[], ) @plugin.on_start() async def __(app): for pl in app.get_plugins(): if isinstance(pl, Plugin) and not pl.name.startswith("$"): plugin.plugins.append(pl) @plugin.on_commands(["plugins"]) async def __(msg, ctx): await ctx.reply(t("Plugins") + ":\n" + "\n".join( "- {} - {}".format(pl.name, pl.description) for pl in plugin.plugins ))
import os import time import psutil from kutana import Plugin, t plugin = Plugin(name=t("Metrics"), description=t("Sends some information (.metrics)")) @plugin.on_commands(["metrics"]) async def __(msg, ctx): process = psutil.Process(os.getpid()) taken_memory = int(process.memory_info().rss / 2**20) taken_time = time.time() - msg.date await ctx.reply("mem: ~{}mib; tim: {}s".format(taken_memory, taken_time))
from kutana import Plugin, t from utils.database import Database plugin = Plugin(name=t("HelperDialog")) cursor = Database.cursor() @plugin.on_commands(["start_helper"]) async def __(msg, ctx): cursor.execute("SELECT user FROM query WHERE helper is NULL LIMIT 1") user = cursor.fetchone() if user: user_id = user[0] cursor.execute("UPDATE query SET helper = ? WHERE user = ?", [msg.sender_id, user_id]) Database.commit() await ctx.reply("Собеседник найден. Общайтесь!") await ctx.send_message(user_id, "Собеседник найден. Общайтесь!") else: await ctx.reply( "Собеседник не найден. Попробуйте повторить поиск через некоторое время" )
from kutana import Plugin, t plugin = Plugin(name=t("Echo"), description=t("Sends your messages back (.echo)")) @plugin.on_commands(["echo"]) async def __(msg, ctx): await ctx.reply("{}".format(ctx.body or '(/)'), attachments=msg.attachments, disable_mentions=0)