mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 13:12:35 +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 csv
|
||||||
import time
|
import time
|
||||||
import codecs
|
import codecs
|
||||||
|
import string
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import os.path
|
import os.path
|
||||||
import threading
|
import threading
|
||||||
@ -321,13 +322,19 @@ class ChannelIdDatabasePlugin(callbacks.Plugin):
|
|||||||
self.db.close()
|
self.db.close()
|
||||||
self.__parent.die()
|
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):
|
def getCommandHelp(self, name, simpleSyntax=None):
|
||||||
help = self.__parent.getCommandHelp(name, simpleSyntax)
|
helpTemplate = self.__parent.getCommandHelp(name, simpleSyntax)
|
||||||
help = help.replace('$Types', format('%p', self.name()))
|
return helpTemplate.substitute(self._typeSubstitutions())
|
||||||
help = help.replace('$Type', self.name())
|
|
||||||
help = help.replace('$types', format('%p', self.name().lower()))
|
|
||||||
help = help.replace('$type', self.name().lower())
|
|
||||||
return help
|
|
||||||
|
|
||||||
def noSuchRecord(self, irc, channel, id):
|
def noSuchRecord(self, irc, channel, id):
|
||||||
irc.error(_('There is no %s with id #%s in my database for %s.') %
|
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'))])
|
additional(rest('glob'))])
|
||||||
|
|
||||||
def showRecord(self, record):
|
def showRecord(self, record):
|
||||||
name = getUserName(record.by)
|
template = string.Template(conf.supybot.reply.format.databaseRecord())
|
||||||
return format(_('%s #%s: %q (added by %s at %t)'),
|
return template.substitute(
|
||||||
self.name(), record.id, record.text, name, record.at)
|
id=record.id,
|
||||||
|
text=record.text,
|
||||||
|
username=getUserName(record.by),
|
||||||
|
at=record.at,
|
||||||
|
**self.typeSubstitutions(),
|
||||||
|
)
|
||||||
|
|
||||||
def get(self, irc, msg, args, channel, id):
|
def get(self, irc, msg, args, channel, id):
|
||||||
"""[<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)
|
return originalCommaAndify(seq, *args, **kwargs)
|
||||||
utils.str.commaAndify = commaAndify
|
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',
|
registerGlobalValue(supybot.reply, 'maximumLength',
|
||||||
registry.Integer(512*256, _("""Determines the absolute maximum length of
|
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
|
the bot's reply -- no reply will be passed through the bot with a length
|
||||||
|
Loading…
Reference in New Issue
Block a user