From 37a93e2485ee87ef094fcc3aabfe1f5b7f12cc68 Mon Sep 17 00:00:00 2001 From: Mal Hancock Date: Fri, 25 Jan 2019 12:40:46 -0800 Subject: [PATCH] add timestamp functionality --- README.md | 7 +++++-- pinhook/bot.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 970a9fa..ea46a9c 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,16 @@ def test_plugin(msg): The function will need to accept a single argument in order to accept a `Message` object from the bot. The `Message` object has the following attributes: -* `cmd`: the command that triggered the function +* `cmd`: (for command plugins) the command that triggered the function * `nick`: the user who triggered the command -* `arg`: all the trailing text after the command. This is what you will use to get optional information for the command +* `arg`: (for command plugins) all the trailing text after the command. This is what you will use to get optional information for the command +* `text`: (for listener plugins) the entire text of the message * `channel`: the channel where the command was initiated * `ops`: the list of bot operators * `botnick`: the nickname of the bot * `logger`: instance of `Bot`'s logger +* `datetime`: aware `datetime.datetime` object when the `Message` object was created +* `timestamp`: float for the unix timestamp when the `Message` object was created It also contains the following IRC functions: * `privmsg`: send a message to an arbitrary channel or user diff --git a/pinhook/bot.py b/pinhook/bot.py index d5a7b4b..bbc02dc 100644 --- a/pinhook/bot.py +++ b/pinhook/bot.py @@ -1,3 +1,4 @@ +from datetime import datetime, timezone import imp import logging import os @@ -28,6 +29,8 @@ class Bot(irc.bot.SingleServerIRCBot): class Message: def __init__(self, channel, nick, botnick, ops, logger, action, privmsg, notice, cmd=None, arg=None, text=None, nick_list=None): + self.datetime = datetime.now(timezone.utc) + self.timestamp = self.datetime.timestamp() self.channel = channel self.nick = nick self.nick_list = nick_list