mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 05:02:32 +01:00
ChannelIdDatabasePlugin: Make the format of showRecord() configurable.
This commit is contained in:
parent
dc736799b8
commit
4046a1b201
@ -33,6 +33,7 @@ import os
|
||||
import csv
|
||||
import time
|
||||
import codecs
|
||||
import string
|
||||
import fnmatch
|
||||
import os.path
|
||||
import threading
|
||||
@ -321,13 +322,19 @@ class ChannelIdDatabasePlugin(callbacks.Plugin):
|
||||
self.db.close()
|
||||
self.__parent.die()
|
||||
|
||||
def typeSubstitutions(self):
|
||||
"""Returns a dict with keys Types/Type/types/type, whose values are
|
||||
the plugin name with matching capitalization and plural."""
|
||||
return {
|
||||
'Types': format('%p', self.name()),
|
||||
'Type': self.name(),
|
||||
'types': format('%p', self.name().lower()),
|
||||
'type': self.name().lower(),
|
||||
}
|
||||
|
||||
def getCommandHelp(self, name, simpleSyntax=None):
|
||||
help = self.__parent.getCommandHelp(name, simpleSyntax)
|
||||
help = help.replace('$Types', format('%p', self.name()))
|
||||
help = help.replace('$Type', self.name())
|
||||
help = help.replace('$types', format('%p', self.name().lower()))
|
||||
help = help.replace('$type', self.name().lower())
|
||||
return help
|
||||
helpTemplate = self.__parent.getCommandHelp(name, simpleSyntax)
|
||||
return helpTemplate.substitute(self._typeSubstitutions())
|
||||
|
||||
def noSuchRecord(self, irc, channel, id):
|
||||
irc.error(_('There is no %s with id #%s in my database for %s.') %
|
||||
@ -436,9 +443,14 @@ class ChannelIdDatabasePlugin(callbacks.Plugin):
|
||||
additional(rest('glob'))])
|
||||
|
||||
def showRecord(self, record):
|
||||
name = getUserName(record.by)
|
||||
return format(_('%s #%s: %q (added by %s at %t)'),
|
||||
self.name(), record.id, record.text, name, record.at)
|
||||
template = string.Template(conf.supybot.reply.format.databaseRecord())
|
||||
return template.substitute(
|
||||
id=record.id,
|
||||
text=record.text,
|
||||
username=getUserName(record.by),
|
||||
at=record.at,
|
||||
**self.typeSubstitutions(),
|
||||
)
|
||||
|
||||
def get(self, irc, msg, args, channel, id):
|
||||
"""[<channel>] <id>
|
||||
|
10
src/conf.py
10
src/conf.py
@ -501,6 +501,16 @@ def commaAndify(seq, *args, **kwargs):
|
||||
return originalCommaAndify(seq, *args, **kwargs)
|
||||
utils.str.commaAndify = commaAndify
|
||||
|
||||
class DatabaseRecordTemplatedString(registry.TemplatedString):
|
||||
requiredTemplates = ['text']
|
||||
|
||||
registerChannelValue(supybot.reply.format, 'databaseRecord',
|
||||
DatabaseRecordTemplatedString(_('$Type #$id: $text (added by $username at $at)'),
|
||||
_("""Format used by generic database plugins (Lart, Dunno, Prase, Success,
|
||||
Quote, ...) to show an entry. You can use the following variables:
|
||||
$type/$types/$Type/$Types (plugin name and variants), $id, $text,
|
||||
$userid/$username (author), $at (creation time).""")))
|
||||
|
||||
registerGlobalValue(supybot.reply, 'maximumLength',
|
||||
registry.Integer(512*256, _("""Determines the absolute maximum length of
|
||||
the bot's reply -- no reply will be passed through the bot with a length
|
||||
|
Loading…
Reference in New Issue
Block a user