當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。