本文整理汇总了Python中system.command_manager.CommandManager类的典型用法代码示例。如果您正苦于以下问题:Python CommandManager类的具体用法?Python CommandManager怎么用?Python CommandManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: UrbanDictionaryPlugin
class UrbanDictionaryPlugin(plugin.PluginObject):
commands = None
config = None
def setup(self):
### Grab important shit
self.commands = CommandManager()
### Register commands
self.commands.register_command("urbandictionary",
self.urbandictionary_cmd,
self,
"urbandictionary.definition",
aliases=["ud"], default=True)
def urbandictionary_cmd(self, protocol, caller, source, command, raw_args,
parsed_args):
args = raw_args.split() # Quick fix for new command handler signature
### Get LastFM username to use
username = None
if len(args) == 0:
caller.respond("Usage: {CHARS}urbandictionary <term>")
return
term = " ".join(args)
try:
definition, permalink = self.get_definition(term)
if definition is None:
source.respond('[UD] "%s" is not defined yet' % term)
else:
# TODO: Limit definition length
source.respond('[UD] "%s" - %s - (%s)' %
(term,
to_bytes(definition)
.replace('\r', '')
.replace('\n', ' '),
to_bytes(permalink)))
except:
self.logger.exception("Cannot get definition for '%s'" % term)
source.respond("There was an error while fetching the definition -"
" please try again later, or alert a bot admin.")
def get_definition(self, term):
request = urllib2.Request("http://api.urbandictionary.com/v0/define?" +
urllib.urlencode({'term': term}))
# Fuck you PEP8. Fuck you with the largest, spikiest dragon dildo, in
# every orifice you have, and more.
request.add_header('User-agent', 'Mozilla/5.0 '
'(X11; U; Linux i686; '
'en-US; rv:1.9.0.1) '
'Gecko/2008071615 '
'Fedora/3.0.1-1.fc9-1.fc9 '
'Firefox/3.0.1')
try:
definition = json.load(urllib2.urlopen(request))["list"][0]
return definition["definition"], definition["permalink"]
except IndexError:
return None, None
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:60,代码来源:__init__.py
示例2: RoulettePlugin
class RoulettePlugin(plugin.PluginObject):
commands = None
channels = {}
users = {}
def setup(self):
self.commands = CommandManager()
self.commands.register_command("rroulette", self.play, self,
"russianroulette.rroulette",
aliases=["roulette"], default=True)
def addChannel(self, channel):
if channel not in self.channels.keys():
players = []
curplayers = []
shots = 0
deaths = 0
chambers = 6
data = {"players": players, "shots": shots, "deaths": deaths,
"chambers": chambers, "curplayers": curplayers}
self.channels[channel] = data
def play(self, protocol, caller, source, command, raw_args,
parsed_args):
args = raw_args.split() # Quick fix for new command handler signature
self.logger.trace("Caller: %s" % repr(caller))
self.logger.trace("Source: %s" % repr(source))
self.logger.trace("Result: %s" % isinstance(source, Channel))
if not isinstance(source, Channel):
caller.respond("This command may only be used in a channel.")
return
self.addChannel(source.name)
chambers_left = self.channels[source.name]["chambers"]
random.seed()
if random.randint(1, chambers_left) == 1:
# Boom!
source.respond("BANG")
protocol.send_action(source, "*reloads the gun*")
chambers_left = 6
source.respond(
'There are %s new chambers. You have a %s%% chance of dying.'
% (chambers_left, int(100.0 / chambers_left)))
else:
# Click..
chambers_left -= 1
source.respond(
'*click* You\'re safe for now. There are %s chambers left. '
'You have a %s%% chance of dying.'
% (chambers_left, int(100.0 / chambers_left)))
self.channels[source.name]["chambers"] = chambers_left
开发者ID:domainr,项目名称:Ultros-contrib,代码行数:59,代码来源:__init__.py
示例3: ItemsPlugin
class ItemsPlugin(plugin.PluginObject):
commands = None
config = None
data = None
storage = None
handler = None
@property
def storage_type(self):
if self.config["storage"].lower() == "json":
return "json"
return "sqlite"
def setup(self):
self.commands = CommandManager()
self.storage = StorageManager()
self.logger.trace("Entered setup method.")
try:
self.config = self.storage.get_file(self, "config", YAML,
"plugins/items.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.warn("Defaulting to SQLite for storage.")
else:
if not self.config.exists:
self.logger.warn("Unable to find config/plugins/items.yml")
self.logger.warn("Defaulting to SQLite for storage.")
else:
self.logger.info("Using storage type: %s" % self.storage_type)
self._load()
self.config.add_callback(self._load)
self.commands.register_command("give", self.give_command, self,
"items.give", default=True)
self.commands.register_command("get", self.get_command, self,
"items.get", default=True)
def _load(self):
if self.storage_type == "json":
self.handler = JSONType(self, self.storage, self.logger)
else:
self.handler = SQLiteType(self, self.storage, self.logger)
@RateLimiter(5, 0, 10)
def give_command(self, *args, **kwargs):
return self.handler.give_command(*args, **kwargs)
@RateLimiter(5, 0, 10)
def get_command(self, *args, **kwargs):
return self.handler.get_command(*args, **kwargs)
开发者ID:domainr,项目名称:Ultros-contrib,代码行数:55,代码来源:__init__.py
示例4: MemosPlugin
class MemosPlugin(plugin.PluginObject):
commands = None
events = None
storage = None
# data = None # SQLite for a change
def setup(self):
self.commands = CommandManager()
self.events = EventManager()
self.storage = StorageManager()
# self.data = self.storage.get_file(self, "data", SQLITE,
# "plugins/memos/memos.sqlite")
# with self.data as c:
# # Multiline strings because of an IDE bug
# c.execute("""CREATE TABLE IF NOT EXISTS memos
# (to TEXT, from TEXT, memo TEXT)""")
self.events.add_callback("PreMessageReceived", self,
self.message_received, 0)
self.commands.register_command("memo", self.memo_command, self,
"memo.send", default=True)
def save_memo(self, sender, recipient, memo):
recipient = recipient.lower()
# with self.data as c:
# c.execute("""INSERT INTO memos VALUES (?, ?, ?)""",
# (recipient, sender, memo))
def get_memos(self, recipient):
recipient = recipient.lower()
# with self.data as c:
# c.execute("""SELECT * FROM memos WHERE from=?""", (recipient,))
# d = c.fetchall()
# return d
def message_received(self, event=PreMessageReceived):
user = event.source
target = event.target if isinstance(event.target, Channel) else user
memos = self.get_memos(user.name)
if memos:
for memo in memos:
sender = memo[1]
text = memo[2]
target.respond("Memo for %s (from %s): %s" % (user.name,
sender, text))
def memo_command(self, protocol, caller, source, command, raw_args,
parsed_args):
args = raw_args.split() # Quick fix for new command handler signature
raise NotImplementedError("This isn't done yet.")
开发者ID:case,项目名称:Ultros-contrib,代码行数:53,代码来源:__init__.py
示例5: ExamplePlugin
class ExamplePlugin(plugin.PluginObject): # Create the plugin class
"""
Example plugin object
"""
commands = None
def setup(self):
"""
Called when the plugin is loaded. Performs initial setup.
"""
# Get an instance of the command manager
self.commands = CommandManager()
# Register the command in our system
self.commands.register_command(
"example", # The name of the command
self.example_command, # The command's function
self, # This plugin
# permission="example.example", # Required permission for command
default=True # Whether this command should be available to all
)
self.commands.register_command( # Another example command
"example2", self.example_command, self, default=True
)
def example_command(self, protocol, caller, source, command, raw_args,
args):
"""
Command handler for the example command
"""
if args is None:
# You'll probably always want this, so you always have
# arguments if quote-parsing fails
args = raw_args.split()
# Send to the channel
source.respond("Hello, world! You ran the %s command!" % command)
# Send to the user that ran the command
caller.respond("Raw arguments: %s" % raw_args)
caller.respond("Parsed arguments: %s" % args)
# Send directly through the protocol
protocol.send_msg(source.name, "Message through the protocol!")
开发者ID:NotAFile,项目名称:Ultros,代码行数:48,代码来源:__init__.py
示例6: setup
def setup(self):
### Grab important shit
self.commands = CommandManager()
self.storage = StorageManager()
### Initial config load
try:
self._config = self.storage.get_file(self,
"config",
YAML,
"plugins/8ball.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.error("Disabling...")
self._disable_self()
return
if not self._config.exists:
self.logger.error("Unable to find config/plugins/8ball.yml")
self.logger.error("Disabling...")
self._disable_self()
return
### Setup some stuff
self._random = random.Random()
self._question_regex = re.compile("[\W_]+")
### Register commands
self.commands.register_command("8ball",
self.eight_ball_cmd,
self,
"8ball.8ball",
default=True)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:32,代码来源:__init__.py
示例7: setup
def setup(self):
### Grab important shit
self._commands = CommandManager()
self._storage = StorageManager()
### Initial config load
try:
self._config = self._storage.get_file(self, "config", YAML,
"plugins/dice.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.error("Disabling...")
self._disable_self()
return
if not self._config.exists:
self.logger.error("Unable to find config/plugins/dice.yml")
self.logger.error("Disabling...")
self._disable_self()
return
### Register commands
self._commands.register_command("roll",
self.roll_cmd,
self,
"dice.roll",
aliases=["dice"],
default=True)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:27,代码来源:__init__.py
示例8: setup
def setup(self):
self.logger.trace("Entered setup method.")
self.storage = StorageManager()
try:
self.config = self.storage.get_file(self, "config", YAML,
"plugins/minecraft.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self._disable_self()
return
if not self.config.exists:
self.logger.error("Unable to find config/plugins/minecraft.yml")
self.logger.error("Disabling..")
self._disable_self()
return
if not self.relay_targets:
self.logger.warn("No valid target protocols found. "
"Disabling status relaying.")
self.commands = CommandManager()
self.commands.register_command("mcquery", self.query_command, self,
"minecraft.query", default=True)
if self.do_relay:
reactor.callLater(30, self.start_relay)
开发者ID:case,项目名称:Ultros-contrib,代码行数:26,代码来源:__init__.py
示例9: setup
def setup(self):
self.storage = StorageManager()
try:
self.config = self.storage.get_file(self, "config", YAML,
"plugins/wordnik.yml")
except Exception:
self.logger.exception("Unable to load the configuration!")
return self._disable_self()
if not self.config.exists:
self.logger.error("Unable to find the configuration at "
"config/plugins/wordnik.yml - Did you fill "
"it out?")
return self._disable_self()
if "apikey" not in self.config or not self.config["apikey"]:
self.logger.error("Unable to find an API key; did you fill out the"
" config?")
return self._disable_self()
self._load()
self.config.add_callback(self._load)
self.plugman = PluginManager()
self.commands = CommandManager()
self.commands.register_command("dict", self.dict_command,
self, "wordnik.dict", default=True)
self.commands.register_command("wotd", self.wotd_command,
self, "wordnik.wotd", default=True)
开发者ID:case,项目名称:Ultros-contrib,代码行数:29,代码来源:__init__.py
示例10: setup
def setup(self):
self.logger.trace("Entered setup method.")
self.commands = CommandManager()
self.events = EventManager()
self.storage = StorageManager()
try:
self.config = self.storage.get_file(self, "config", YAML,
"plugins/inter.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.error(_("Disabling.."))
self._disable_self()
return
if not self.config.exists:
self.logger.error("Unable to find config/plugins/inter.yml")
self.logger.error(_("Disabling.."))
self._disable_self()
return
self.config.add_callback(self.reload)
self.commands.register_command("players", self.players_command, self,
"inter.players", default=True)
self.events.add_callback("ReactorStarted", self, self.first_load, 0)
开发者ID:domainr,项目名称:Ultros-contrib,代码行数:28,代码来源:__init__.py
示例11: setup
def setup(self):
self.commands = CommandManager()
self.commands.register_command("hb",
self.hb_command,
self,
"hb.hb", default=True)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:7,代码来源:__init__.py
示例12: setup
def setup(self):
self.commands = CommandManager()
self.storage = StorageManager()
self.logger.trace("Entered setup method.")
try:
self.config = self.storage.get_file(self, "config", YAML,
"plugins/items.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.warn("Defaulting to SQLite for storage.")
else:
if not self.config.exists:
self.logger.warn("Unable to find config/plugins/items.yml")
self.logger.warn("Defaulting to SQLite for storage.")
else:
self.logger.info("Using storage type: %s" % self.storage_type)
self._load()
self.config.add_callback(self._load)
self.commands.register_command("give", self.give_command, self,
"items.give", default=True)
self.commands.register_command("get", self.get_command, self,
"items.get", default=True)
self.commands.register_command("items", self.count_command, self,
"items.count", default=True)
开发者ID:case,项目名称:Ultros-contrib,代码行数:27,代码来源:__init__.py
示例13: __init__
def __init__(self):
self.commands = CommandManager()
self.event_manager = EventManager()
self.logger = getLogger("Manager")
self.plugman = PluginManager(self)
self.yapsy_logger = getLogger("yapsy")
self.metrics = None
开发者ID:NotAFile,项目名称:Ultros,代码行数:8,代码来源:factory_manager.py
示例14: setup
def setup(self):
"""
Called when the plugin is loaded. Performs initial setup.
"""
self.commands = CommandManager()
self.commands.register_command("page", self.page_command, self,
default=True)
开发者ID:NotAFile,项目名称:Ultros,代码行数:8,代码来源:__init__.py
示例15: setup
def setup(self):
self.commands = CommandManager()
self.goslate = Goslate()
self.commands.register_command(
"translate", self.translate_command, self, "translate.translate",
["tr", "t"], True
)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:8,代码来源:__init__.py
示例16: setup
def setup(self):
self.commands = CommandManager()
self.events = EventManager()
self.storage = StorageManager()
self.data = self.storage.get_file(
self,
"data",
DBAPI,
"sqlite3:data/plugins/lastseen/users.sqlite",
"data/plugins/lastseen/users.sqlite",
check_same_thread=False
)
self.data.runQuery("CREATE TABLE IF NOT EXISTS users ("
"user TEXT, "
"protocol TEXT, "
"at INTEGER)")
self.commands.register_command("seen", self.seen_command, self,
"seen.seen", default=True)
# General events
self.events.add_callback("PreMessageReceived", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_source_caller])
self.events.add_callback("PreCommand", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_source_caller])
self.events.add_callback("NameChanged", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("UserDisconnected", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
# Mumble events
self.events.add_callback("Mumble/UserRemove", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("Mumble/UserJoined", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("Mumble/UserMoved", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("Mumble/UserSelfMuteToggle", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("Mumble/UserSelfDeafToggle", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
self.events.add_callback("Mumble/UserRecordingToggle", self,
self.event_handler, 0, cancelled=True,
extra_args=[self.event_user_caller])
开发者ID:domainr,项目名称:Ultros-contrib,代码行数:56,代码来源:__init__.py
示例17: setup
def setup(self):
### Grab important shit
self.commands = CommandManager()
### Register commands
self.commands.register_command("urbandictionary",
self.urbandictionary_cmd,
self,
"urbandictionary.definition",
aliases=["ud"], default=True)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:10,代码来源:__init__.py
示例18: HeartbleedPlugin
class HeartbleedPlugin(plugin.PluginObject):
commands = None
def setup(self):
self.commands = CommandManager()
self.commands.register_command("hb",
self.hb_command,
self,
"hb.hb", default=True)
@run_async_threadpool
def hb_command(self, protocol, caller, source, command, raw_args,
parsed_args):
args = raw_args.split() # Quick fix for new command handler signature
if len(args) < 1:
caller.respond("Usage: {CHARS}hb <address> [port]")
return
else:
host = args[0]
port = 443
if len(args) > 1:
port = args[1]
try:
port = int(port)
except:
source.respond("Port '%s' is invalid, trying on port "
"443." % port)
try:
source.respond("Checking %s:%s" % (host, port))
result = hb.try_host(host, port)
if result:
source.respond("Host %s is vulnerable!" % host)
elif result is None:
source.respond("Host %s returned an error. It's probably "
"not vulnerable." % host)
else:
source.respond("Host %s is not vulnerable." % host)
except:
self.logger.exception("Error querying host %s" % host)
source.respond("Unable to determine whether host %s is "
"vulnerable." % host)
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:43,代码来源:__init__.py
示例19: setup
def setup(self):
### Grab important shit
self.commands = CommandManager()
self.storage = StorageManager()
### Initial config load
try:
self._config = self.storage.get_file(self,
"config",
YAML,
"plugins/aoshelper.yml")
except Exception:
self.logger.exception("Error loading configuration!")
self.logger.error("Disabling...")
self._disable_self()
return
if not self._config.exists:
self.logger.error("Unable to find config/plugins/aoshelper.yml")
self.logger.error("Disabling...")
self._disable_self()
return
### Load options from config
self._load()
self._config.add_callback(self._load)
### Register commands
self.commands.register_command("aosplayercount",
self.playercount_cmd,
self,
"aoshelper.playercount",
[
"playercount"
], default=True)
self.commands.register_command("aostoip",
self.aos_to_ip_command,
self,
"aoshelper.aostoip",
[
"aos2ip"
])
self.commands.register_command("iptoaos",
self.ip_to_aos_command,
self,
"aoshelper.iptoaos",
[
"ip2aos"
])
### Setup soem variables
self._last_update_voxlap = 0
self._last_update_steam = 0
self._last_voxlap_player_count = -1
self._last_steam_player_count = -1
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:55,代码来源:__init__.py
示例20: TranslatePlugin
class TranslatePlugin(PluginObject):
commands = None
goslate = None
def setup(self):
self.commands = CommandManager()
self.goslate = Goslate()
self.commands.register_command(
"translate", self.translate_command, self, "translate.translate",
["tr", "t"], True
)
@run_async_threadpool
def translate_command(self, protocol, caller, source, command, raw_args,
parsed_args):
if len(parsed_args) < 2:
caller.respond(
"Usage: {CHARS}" + command + " <languages> <text>"
)
return
langs = parsed_args[0]
text = u" ".join([to_unicode(x) for x in parsed_args[1:]])
if u":" in langs:
split = langs.split(u":")
from_lang, to_lang = split[0], split[1]
else:
from_lang, to_lang = u"", langs
try:
translation = self.goslate.translate(text, to_lang, from_lang)
source.respond(u"[{}] {}".format(to_lang, translation))
except Error as e:
source.respond(u"Translation error: {}".format(e))
except Exception as e:
self.logger.exception("Translation error")
source.respond(u"Translation error: {}".format(e))
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:40,代码来源:__init__.py
注:本文中的system.command_manager.CommandManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论