def alarm(bot, job): """Send the ping message.""" query = Message.select().where(Message.chat_id == job.context) \ .order_by(Message.created.desc()).get() text = (f"[{query.to_user}](tg://user?id={query.to_user_id}) " + f"Ping!\n{query.content}") bot.send_message(job.context, text=text, parse_mode=ParseMode.MARKDOWN)
def get_messages_for_member(self, member_id): """Gets all messages for the chosen member. Args: member_id: Unique discord id for that member. Returns: A list of message records. """ return list(Message.select().where(Message.member == member_id))
def get_message_count_over_period(self, period): """Gets the number of messages posted by date. Args: period: The period over which to count messages, can be "day" or "week". Returns: A list of objects containing a date and a count (number of messages posted that day) for every date where a message was posted on the channel. """ if period == "week": query = Message.select(db.truncate_date("day", Message.date).alias("date"), fn.Count(Message.id)) \ .group_by(db.truncate_date("day", Message.date)) elif period == "day": query = Message.select(Message.date.hour.alias("date"), fn.Count(Message.id)) \ .group_by(Message.date.hour) else: raise ValueError("Unknown period.") return list(query)
def get_message(self, message_id): """Gets a message from the database. Args: message_id: The message's uid in the database. Returns: A message record. """ return Message.select().where(Message.id == message_id).first()
def __init__(self, parent): super(MessagesTable, self).__init__(parent) for message in Message.select().order_by(('date', 'desc')).limit(10): self.data.append((message.display_date, display_phone_number(message.identity), message.text)) self.hheaders = [u"Date", u"Expéditeur", u"Message"] self.display_vheaders = False self.stretch_columns = [2,] self.max_rows = 8 self.align_map = {0: 'l', 1: 'l', 2:'l'} self.refresh()