示例#1
0
    def setUp(self):
        self.bot = Bot()
        self.bot.connection.close = MagicMock()
        db.insert = MagicMock()
        db.delete = MagicMock()
        db.select = MagicMock(return_value=[905])
        senadores.fetch_ids = MagicMock(return_value=[905])
        senadores.fetch_detail = MagicMock(return_value='senador')

        periodos.fetch_periodos = MagicMock(return_value='periodos')

        proyectos.fetch_resumen = MagicMock()
        proyectos.fetch_autores = MagicMock(return_value=[[905, 1], [905, 2]])
        proyectos.fetch_new_proyectos = MagicMock(
            return_value=[{
                'fecha': datetime.now().date(),
                'boletin': 905,
                'estado': 'test'
            }])

        comisiones.fetch_detail = MagicMock()
        comisiones.fetch_integrantes = MagicMock(return_value=[{
            'cid': 805,
            'pid': 2
        }])
        comisiones.fetch_proyectos_in_comision = MagicMock(
            return_value=set(['0-0', '1-0']))
        comisiones.fetch_new_comisiones = MagicMock(
            return_value=[{
                'id': 905,
                'nombre': 'test',
                'tipo': 'test'
            }])
示例#2
0
    def test_on_event(self):
        event = VkBotMessageEvent(raw=self.RAW_EVENT)

        send_mock = Mock()

        with patch('main.vk_api.VkApi'):
            with patch('main.VkBotLongPoll'):
                bot = Bot('', '')
                bot.api = Mock()
                bot.api.messages.send = send_mock

                bot.on_event(event)

        send_mock.assert_called_once_with(
            message=self.RAW_EVENT['object']['text'],
            random_id=ANY,
            peer_id=self.RAW_EVENT['object']['peer_id'])
示例#3
0
    def test_bot_start(self):
        count = 5
        obj = [{'a': 1}]
        events = [obj] * count

        long_poller_mock = Mock(return_value=events)
        long_poller_listen_mock = Mock()
        long_poller_listen_mock.listen = long_poller_mock

        with patch('main.vk_api.VkApi'):
            with patch('main.VkBotLongPoll',
                       return_value=long_poller_listen_mock):
                bot = Bot('', '')
                bot.on_event = Mock()
                bot.start()

                bot.on_event.assert_called()
                bot.on_event.assert_any_call(obj)
                assert bot.on_event.call_count == count
示例#4
0
def main():
    DiscordBot = Bot()
    DiscordBot.start_bot()
示例#5
0
文件: lab.py 项目: sseryani/honeybot
from main import Bot_core as Bot

bot = Bot()
print(bot.specific_send_command('#abc', 'greetings'))
示例#6
0
from main import Bot
import time, random, signal
b = Bot()
signal.signal(signal.SIGINT, b.exit)
while True:
    b.run(b.config["searchterm"], b.config["targetlink"])
    waitTime = max(
        b.config["averageinterval"] + random.randrange(
            -b.config["intervalrange"], b.config["intervalrange"]),
        b.config['mininterval'])
    b.log(f"Waiting for {waitTime} second(s) before running again.",
          verbosity=1)
    time.sleep(waitTime)