Beispiel #1
0
def message_new(msg):
    rmsg = bot.module.message.New()
    if command.exec_command(msg, rmsg):
        params = rmsg.vk_object()
        params.update({
            'peer_id': msg['peer_id'],
            'random_id': random.randint(1000000, 9999999)
        })
        bot.module.VK.API.call('messages.send', params)
        console.log('Сообщение: {} | От: {}{}'.format(
            msg['text'], msg['from_id'],
            ' | Чат: {}'.format(msg['peer_id'] - 2000000000)
            if msg['peer_id'] > 2000000000 else ''))
Beispiel #2
0
    def create_config(self):
        console.log("Создание конфигурационного файла...")
        self.config.add_section("bot")
        self.config.set("bot", "access_token", "YOUR_TOKEN")
        self.config.set("bot", "group_id", "YOUR_ID")
        self.config.set("bot", "workers_count", "COUNT")
        self.config.set("bot", "mysql_host", "HOST")
        self.config.set("bot", "mysql_user", "USER")
        self.config.set("bot", "mysql_pass", "PASSWORD")
        self.config.set("bot", "mysql_base", "DATABASE")
        self.config.add_section('binds')
        self.save_config()
        console.process("Был создан новый конфигурационный файл. Пожалуйста,\
 настройте его перед началом использования бота")
        sys.exit(0)
Beispiel #3
0
 def start():
     global config, vk
     console.log(
         "Платформа для разработки чат-ботов ВКонтакте (v.: {}) © 2019".
         format(PLATFORM_VERSION))
     console.log("Чтение конфигурационного файла...")
     config = Config("config")
     console.log("Инициализация и подключение к ВКонтакте...")
     vk = VK(config.get_bot()['access_token'], config.get_bot()['group_id'])
     console.log("Подключение к боту...")
     assert hasattr(bot, 'init')
     bot.init(vk, config)
     init_workers(int(config.get_bot()['workers_count']))
     vk.listen_longpoll(handle_update)
     console.log("Платформа успешно загружена!")
     cmd.listen(vk, config)
Beispiel #4
0
def init():
    global connections
    connections = {}
    console.log("Подключение к MySQL серверу...")
    bot_config = module.config.get_bot()
    for i in range(1, int(bot_config['workers_count']) + 1):
        connections['Thread-{}'.format(i)] = Connection(
            host=bot_config['mysql_host'],
            user=bot_config['mysql_user'],
            passwd=bot_config['mysql_pass'],
            db=bot_config['mysql_base'],
            use_unicode=True,
            charset="utf8",
            cursorclass=cursors.DictCursor)
    connections['MainThread'] = Connection(host=bot_config['mysql_host'],
                                           user=bot_config['mysql_user'],
                                           passwd=bot_config['mysql_pass'],
                                           db=bot_config['mysql_base'],
                                           use_unicode=True,
                                           charset="utf8",
                                           cursorclass=cursors.DictCursor)
Beispiel #5
0
def init(this_vk, this_config):
    bot.module.VK = this_vk
    bot.module.config = this_config
    console.log("Подключение модулей...")
    bot.module.load_modules()
    console.log("Загрузка команд...")
    command.load_commands()
    console.log("Загружено {} команд".format(len(command.commands)))
Beispiel #6
0
 def save_config(self):
     with open(self.name, "w") as file:
         self.config.write(file)
     console.log("Конфигурационный файл \"{}\" успешно сохранён!".format(self.name))