コード例 #1
0
 def assert_length(self):
     message_length = len(self.getMessageParts()) - 1
     if self.length['min'] != False:
         if message_length < self.length['min']:
             raise DiscordError('Missing arguments!')
     if self.length['max'] != False:
         if message_length > self.length['max']:
             raise DiscordError('Too many arguments!')
コード例 #2
0
 def run(self, client):
     self.assert_length()
     self.assert_valid()
     message_parts = self.getMessageParts()
     tag='main'
     if len(message_parts) > 1:
         tag=message_parts[1]
     p = parameter.getInstance()
     cfg = p.__config__
     tags = []
     if tag == 'all':
         for section in cfg.sections():
             if section.endswith(':' + self.message.server.id):
                 tags.append(section.split(':')[0])
     else:
         tags.append(tag)
     message=''
     for tag in tags:
         keyindex=tag + ':' + self.message.server.id
         if not keyindex in cfg.sections():
             raise DiscordError('No server with the tag "%s" found.' % (tag))
         game = cfg.get(keyindex, 'game')
         ip = cfg.get(keyindex, 'ip')
         port = cfg.get(keyindex, 'port')
         gs = queryli(game, ip, int(port))
         printAll = False
         if len(self.getMessageParts()) > 2:
             printAll=True
         message+=format_message(self.message.server.id, gs, game, printAll, False)
     yield from client.send_message(self.message.channel, message)
コード例 #3
0
 def run(self, client):
     self.assert_permission()
     self.assert_length()
     self.assert_valid()
     message_parts = self.getMessageParts()
     p = parameter.getInstance()
     cfg = p.__config__
     if not self.message.server.id in cfg.sections():
         cfg.add_section(self.message.server.id)
     cfg.set(self.message.server.id, message_parts[1], 'false')
     server_uid = message_parts[1] + ':' + self.message.server.id
     if server_uid in cfg.sections():
         raise DiscordError(
             "Server with the tag \"%s\" is already configured, delete server first: !delserver <tag>"
             % (message_parts[1]))
     else:
         cfg.add_section(server_uid)
     cfg.set(server_uid, 'game', message_parts[2])
     cfg.set(server_uid, 'ip', message_parts[3])
     cfg.set(server_uid, 'port', message_parts[4])
     with open(p.getConfig(), 'w+') as f:
         cfg.write(f)
     yield from client.send_message(
         self.message.channel, 'Added %s server %s with address %s:%s' %
         (message_parts[2], message_parts[1], message_parts[3],
          message_parts[4]))
コード例 #4
0
 def assert_valid(self):
     message_parts = self.getMessageParts()
     for key in range(1, len(message_parts)):
         if key in self.validationRules:
             reg = re.compile(self.validationRules[key])
             if not bool(reg.match(message_parts[key])):
                 raise DiscordError('Invalid format for the ' +
                                    self.ndarg(key - 1) +
                                    ' argument, only ' +
                                    self.validationRules[key] +
                                    ' is allowed!')
コード例 #5
0
 def run(self, client):
     self.assert_length()
     p = parameter.getInstance()
     cfg = p.__config__
     if not self.message.server.id in cfg.sections():
         cfg.add_section(self.message.server.id)
     tags = []
     for section in cfg.sections():
         if section.endswith(':' + self.message.server.id):
             tags.append(section.split(':')[0])
     if len(tags) == 0:
         raise DiscordError('No servers configured!')
     yield from client.send_message(self.message.channel, 'Currently the following tags are configured:' + self.format_list(tags))
コード例 #6
0
 def run(self, client):
     self.assert_length()
     self.assert_valid()
     message_parts = self.getMessageParts()
     tag = message_parts[1]
     p = parameter.getInstance()
     cfg = p.__config__
     keyindex = tag + ':' + self.message.server.id
     if not keyindex in cfg.sections():
         raise DiscordError('No server with the tag "%s" found.' % (tag))
     game = cfg.get(keyindex, 'game')
     ip = cfg.get(keyindex, 'ip')
     port = cfg.get(keyindex, 'port')
     yield from client.send_message(
         self.message.channel,
         '```ini\nip = %s\nport = %s\ngame = %s```' % (ip, port, game))
コード例 #7
0
 def assert_permission(self):
     if not self.message.author.server_permissions.manage_server:
         raise DiscordError('Missing permissions')