butterrobot/butterrobot_plugins_contrib/dev.py

19 lines
539 B
Python
Raw Normal View History

2020-04-22 21:58:06 +00:00
from datetime import datetime
from butterrobot.plugins import Plugin
from butterrobot.objects import Message
class PingPlugin(Plugin):
name = "Ping command"
id = "contrib.dev.ping"
2020-04-22 21:58:06 +00:00
@classmethod
def on_message(cls, message, **kwargs):
2020-04-22 21:58:06 +00:00
if message.text == "!ping":
delta = datetime.now() - message.date
delta_ms = delta.seconds * 1000 + delta.microseconds / 1000
2020-09-17 14:09:31 +00:00
yield Message(
2020-04-22 21:58:06 +00:00
chat=message.chat, reply_to=message.id, text=f"pong! ({delta_ms}ms)",
)