当前位置: 首页>>代码示例>>Python>>正文


Python Permissions.update方法代码示例

本文整理汇总了Python中permissions.Permissions.update方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.update方法的具体用法?Python Permissions.update怎么用?Python Permissions.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在permissions.Permissions的用法示例。


在下文中一共展示了Permissions.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BotState

# 需要导入模块: from permissions import Permissions [as 别名]
# 或者: from permissions.Permissions import update [as 别名]
class BotState(object):
  def __init__(self, bot):
    self.bot = bot
    self.channels_by_id = {}
    self.users_by_session = {}
    self.users_by_id = {}
    self.root = None
    self.permissions = None
    # The user object representing the bot.
    self.user = None
    # The current channel the bot is in.
    self.channel = None

  def get_actor(self, session_id):
    if not session_id in self.users_by_session:
      LOGGER.warning('Invalid session ID: %d.' % session_id)
      return None
    else:
      return self.users_by_session[session_id]

  def get_channel(self, chan_id):
    if not chan_id in self.channels_by_id:
      LOGGER.warning('Invalid Channel ID: %d.' % chan_id)
      return None
    else:
      return self.channels_by_id[chan_id]

  def on_version(self, msg):
    self.version = msg.version
    self.release = msg.release
    self.os = msg.os
    self.os_version = msg.os_version

  def on_voice_ping(self, session_id):
    self.bot.on_voice_ping(session_id)

  def on_voice_talk(self, from_id, sequence, data):
    self.bot.on_voice_talk(self.get_actor(from_id), sequence, data)

  def on_voice_whisper_chan(self, from_id, sequence, data):
    pass

  def on_voice_whisper_self(self, from_id, sequence, data):
    pass

  def on_pingback(self, ping_msec, msg):
    self.ping = ping_msec
    self.packet_stats = (msg.good, msg.late, msg.lost)
    self.udp_stats = (msg.udp_packets, msg.udp_ping_avg, msg.udp_ping_var)

  def on_reject(self, msg):
    self.rejected = True
    self.reject_type = msg.type
    self.reject_reason = msg.reason
    self.bot.rejected()

  def on_server_config(self, msg):
    self.welcome_text = msg.welcome_text
    self.allow_html = msg.allow_html

  def on_server_sync(self, msg):
    self.max_bandwidth = msg.max_bandwidth
    self.welcome_text = msg.welcome_text
    if msg.permissions:
      if not self.permissions:
        self.permissions = Permissions(msg.permissions)
      else:
        self.permissions.update(msg.permissions)
    self.bot.connected()

  def on_channel_state(self, msg):
    if msg.channel_id not in self.channels_by_id:
      chan = Channel(self.bot, msg.channel_id)
      self.channels_by_id[msg.channel_id] = chan
    else:
      chan = self.channels_by_id[msg.channel_id]
    chan.update(msg)

    if msg.parent == msg.channel_id:
      if not msg.channel_id == 0:
        LOGGER.warning('Root channel not ID 0.')
      if self.root and self.root != chan:
        LOGGER.error('Received 2 different roots...?')
        raise Exception('Two roots.')
      self.root = chan
    elif chan.parent:
      if chan.parent.id != msg.parent:
        chan.parent.remove_child(chan)
        self.channels_by_id[msg.parent].add_child(chan)
    else:
      if not msg.parent in self.channels_by_id:
        LOGGER.error('Parent ID passed by server is not in the channel list.')
        raise Exception('Invalid Parent.')
      self.channels_by_id[msg.parent].add_child(chan)

  def on_user_state(self, msg):
    if msg.session not in self.users_by_session:
      user = User(self.bot, msg.session)
      self.users_by_session[msg.session] = user
      if msg.user_id is not None:
#.........这里部分代码省略.........
开发者ID:Hicks85,项目名称:mumble-bots,代码行数:103,代码来源:bot.py


注:本文中的permissions.Permissions.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。