def test_clean_callable_example_nickname(tmpconfig, func): module.commands('test')(func) module.example('$nickname: hello')(func) loader.clean_callable(func, tmpconfig) assert len(func._docs) == 1 assert 'test' in func._docs docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert docs[1] == 'TestBot: hello'
def test_clean_callable_example_user_help(tmpconfig, func): module.commands('test')(func) module.example('.test hello', user_help=True)(func) loader.clean_callable(func, tmpconfig) assert len(func._docs) == 1 assert 'test' in func._docs docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert docs[1] == ['.test hello']
def test_clean_callable_example_not_set(tmpconfig, func): module.commands('test')(func) loader.clean_callable(func, tmpconfig) assert hasattr(func, '_docs') assert len(func._docs) == 1 assert 'test' in func._docs docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert docs[1] == []
def test_clean_callable_example_default_prefix(tmpconfig, func): module.commands('test')(func) module.example('.test hello')(func) tmpconfig.core.help_prefix = '!' loader.clean_callable(func, tmpconfig) assert len(func._docs) == 1 assert 'test' in func._docs docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert docs[1] == '!test hello'
def test_clean_callable_example_first_only(tmpconfig, func): module.commands('test')(func) module.example('.test hello')(func) module.example('.test bonjour')(func) loader.clean_callable(func, tmpconfig) assert len(func._docs) == 1 assert 'test' in func._docs docs = func._docs['test'] assert len(docs) == 2 assert docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert docs[1] == '.test hello'
def test_clean_callable_example_multi_commands(tmpconfig, func): module.commands('test')(func) module.commands('unit')(func) module.example('.test hello')(func) loader.clean_callable(func, tmpconfig) assert hasattr(func, '_docs') assert len(func._docs) == 2 assert 'test' in func._docs assert 'unit' in func._docs test_docs = func._docs['test'] unit_docs = func._docs['unit'] assert len(test_docs) == 2 assert test_docs == unit_docs assert test_docs[0] == inspect.cleandoc(func.__doc__).splitlines() assert test_docs[1] == '.test hello'
'NSV\?': 'NSV means non-scale victory. See https://www.reddit.com/r/loseit/wiki/faq', '.*NSV mean\?': 'NSV means non-scale victory. See https://www.reddit.com/r/loseit/wiki/faq', 'GW\?': 'GW means goal weight. See https://www.reddit.com/r/loseit/wiki/faq', '.*GW mean\?': 'GW means goal weight. See https://www.reddit.com/r/loseit/wiki/faq' } #@module.commands(*commands.keys()) #@module.example('.' + ', .'.join(commands.keys())) #def linkreply(bot, trigger): # bot.reply(commands[trigger.group(1).lower()]) def spontaneous_reply(bot, trigger): bot.say(patterns[trigger.match.re.pattern]) for pattern in patterns.keys(): module.rule(pattern)(spontaneous_reply) def link_reply(bot, trigger): bot.reply(commands[trigger.group(1).lower()]) for command in commands.keys(): module.commands(command)(link_reply)
from sopel import module import sqlite3 module.commands('pickquote') def pickQuote(bot, trigger): conn = sqlite3.connect('/data/project/zppixbot/.sopel/plugins/quotes.db') cursor = conn.execute("SELECT * from quotes ORDER BY RANDOM() LIMIT 1;") quote = row[0] author = row[1] for row in cursor: bot.say(quote + " - " + author) conn.close()