From 7599c206b0dd86168ea7fbfd50187b19bc477a9d Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 19 Jul 2016 23:34:30 +0300 Subject: [PATCH] search plugin + bot update --- Bot/bot.py | 12 +++++++++++ SearchPlugin/srch.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 SearchPlugin/srch.py diff --git a/Bot/bot.py b/Bot/bot.py index d95f888..9616331 100644 --- a/Bot/bot.py +++ b/Bot/bot.py @@ -31,12 +31,22 @@ class Bot(plugin_super_class.PluginSuperClass): def __init__(self, *args): super(Bot, self).__init__('Bot', 'bot', *args) self._callback = None + self._mode = 0 + self._message = "I'm away, will back soon" self._timer = QtCore.QTimer() self._timer.timeout.connect(self.initialize) def start(self): self._timer.start(10000) + def command(self, command): + if command.startswith('mode '): + self._mode = int(command.split(' ')[-1]) + elif command.startswith('message '): + self._message = command[8:] + else: + super().command(command) + def initialize(self): self._timer.stop() self._callback = self._tox.friend_message_cb @@ -55,6 +65,8 @@ class Bot(plugin_super_class.PluginSuperClass): self.stop() def answer(self, friend_number, message): + if not self._mode: + message = self._message invoke_in_main_thread(self._profile.send_message, message, friend_number) diff --git a/SearchPlugin/srch.py b/SearchPlugin/srch.py new file mode 100644 index 0000000..ea2ed97 --- /dev/null +++ b/SearchPlugin/srch.py @@ -0,0 +1,47 @@ +import plugin_super_class +from PySide import QtGui, QtCore + + +class SearchPlugin(plugin_super_class.PluginSuperClass): + + def __init__(self, *args): + super(SearchPlugin, self).__init__('SearchPlugin', 'srch', *args) + + def get_message_menu(self, menu, text): + google = QtGui.QAction( + QtGui.QApplication.translate("srch", "Find in Google", None, QtGui.QApplication.UnicodeUTF8), + menu) + google.triggered.connect(lambda: self.google(text)) + + duck = QtGui.QAction( + QtGui.QApplication.translate("srch", "Find in DuckDuckGo", None, QtGui.QApplication.UnicodeUTF8), + menu) + duck.triggered.connect(lambda: self.duck(text)) + + yandex = QtGui.QAction( + QtGui.QApplication.translate("srch", "Find in Yandex", None, QtGui.QApplication.UnicodeUTF8), + menu) + yandex.triggered.connect(lambda: self.yandex(text)) + + bing = QtGui.QAction( + QtGui.QApplication.translate("srch", "Find in Bing", None, QtGui.QApplication.UnicodeUTF8), + menu) + bing.triggered.connect(lambda: self.bing(text)) + + return [duck, google, yandex, bing] + + def google(self, text): + url = QtCore.QUrl('https://www.google.com/search?q=' + text) + QtGui.QDesktopServices.openUrl(url) + + def duck(self, text): + url = QtCore.QUrl('https://duckduckgo.com/?q=' + text) + QtGui.QDesktopServices.openUrl(url) + + def yandex(self, text): + url = QtCore.QUrl('https://yandex.com/search/?text=' + text) + QtGui.QDesktopServices.openUrl(url) + + def bing(self, text): + url = QtCore.QUrl('https://www.bing.com/search?q=' + text) + QtGui.QDesktopServices.openUrl(url)