mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Aka: Fix encoding for Akas with non-ascii characters in the name.
This commit is contained in:
parent
4cebfb93f4
commit
235854b284
@ -100,6 +100,8 @@ if sqlalchemy:
|
|||||||
|
|
||||||
|
|
||||||
def has_aka(self, channel, name):
|
def has_aka(self, channel, name):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
count = self.get_db(channel).query(Alias) \
|
count = self.get_db(channel).query(Alias) \
|
||||||
.filter(Alias.name == name) \
|
.filter(Alias.name == name) \
|
||||||
.count()
|
.count()
|
||||||
@ -109,6 +111,8 @@ if sqlalchemy:
|
|||||||
return list_
|
return list_
|
||||||
|
|
||||||
def get_alias(self, channel, name):
|
def get_alias(self, channel, name):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
try:
|
try:
|
||||||
return self.get_db(channel).query(Alias.alias) \
|
return self.get_db(channel).query(Alias.alias) \
|
||||||
.filter(Alias.name == name).one()[0]
|
.filter(Alias.name == name).one()[0]
|
||||||
@ -128,11 +132,15 @@ if sqlalchemy:
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def remove_aka(self, channel, name):
|
def remove_aka(self, channel, name):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
db = self.get_db(channel)
|
db = self.get_db(channel)
|
||||||
db.query(Alias).filter(Alias.name == name).delete()
|
db.query(Alias).filter(Alias.name == name).delete()
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def lock_aka(self, channel, name, by):
|
def lock_aka(self, channel, name, by):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
db = self.get_db(channel)
|
db = self.get_db(channel)
|
||||||
try:
|
try:
|
||||||
aka = db.query(Alias) \
|
aka = db.query(Alias) \
|
||||||
@ -147,6 +155,8 @@ if sqlalchemy:
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def unlock_aka(self, channel, name, by):
|
def unlock_aka(self, channel, name, by):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
db = self.get_db(channel)
|
db = self.get_db(channel)
|
||||||
try:
|
try:
|
||||||
aka = db.query(Alias) \
|
aka = db.query(Alias) \
|
||||||
@ -161,6 +171,8 @@ if sqlalchemy:
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def get_aka_lock(self, channel, name):
|
def get_aka_lock(self, channel, name):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
try:
|
try:
|
||||||
return self.get_db(channel) \
|
return self.get_db(channel) \
|
||||||
.query(Alias.locked, Alias.locked_by, Alias.locked_at)\
|
.query(Alias.locked, Alias.locked_by, Alias.locked_at)\
|
||||||
@ -220,6 +232,8 @@ class Aka(callbacks.Plugin):
|
|||||||
self._db = AkaDB()
|
self._db = AkaDB()
|
||||||
|
|
||||||
def isCommandMethod(self, name):
|
def isCommandMethod(self, name):
|
||||||
|
if sys.version_info[0] < 3 and isinstance(name, str):
|
||||||
|
name = name.decode('utf8')
|
||||||
channel = dynamic.channel or 'global'
|
channel = dynamic.channel or 'global'
|
||||||
return self._db.has_aka(channel, name) or \
|
return self._db.has_aka(channel, name) or \
|
||||||
self._db.has_aka('global', name) or \
|
self._db.has_aka('global', name) or \
|
||||||
@ -348,8 +362,8 @@ class Aka(callbacks.Plugin):
|
|||||||
alias += ' $*'
|
alias += ' $*'
|
||||||
try:
|
try:
|
||||||
self._add_aka(channel, name, alias)
|
self._add_aka(channel, name, alias)
|
||||||
self.log.info('Adding Aka %q for %q (from %s)',
|
self.log.info('Adding Aka %r for %r (from %s)' % (
|
||||||
name, alias, msg.prefix)
|
name, alias, msg.prefix))
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except AkaError as e:
|
except AkaError as e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
@ -371,7 +385,7 @@ class Aka(callbacks.Plugin):
|
|||||||
channel = arg
|
channel = arg
|
||||||
try:
|
try:
|
||||||
self._remove_aka(channel, name)
|
self._remove_aka(channel, name)
|
||||||
self.log.info('Removing Aka %q (from %s)', name, msg.prefix)
|
self.log.info('Removing Aka %r (from %s)' % (name, msg.prefix))
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except AkaError as e:
|
except AkaError as e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
@ -134,6 +134,10 @@ class AkaChannelTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('aka add egg "echo qux"')
|
self.assertNotError('aka add egg "echo qux"')
|
||||||
self.assertResponse('egg', 'baz')
|
self.assertResponse('egg', 'baz')
|
||||||
|
|
||||||
|
def testComplicatedNames(self):
|
||||||
|
self.assertNotError(u'aka add café "echo coffee"')
|
||||||
|
self.assertResponse(u'café', 'coffee')
|
||||||
|
|
||||||
class AkaTestCase(PluginTestCase):
|
class AkaTestCase(PluginTestCase):
|
||||||
plugins = ('Aka', 'User')
|
plugins = ('Aka', 'User')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user