Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Adding Pushbullet integration #162

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pynput==1.7.6
pywinctl==0.0.42
requests==2.28.1
simplejson==3.17.6
pushbullet-python==1.7.0
2 changes: 1 addition & 1 deletion src/OSBC.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def __init_settings(self):
# ============ Button Handlers ============
def __on_settings_clicked(self):
window = customtkinter.CTkToplevel(master=self)
window.geometry("540x287")
window.geometry("540x400")
window.title("Settings")
view = SettingsView(parent=window)
view.pack(side="top", fill="both", expand=True, padx=20, pady=20)
Expand Down
10 changes: 10 additions & 0 deletions src/model/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from abc import ABC, abstractmethod
from enum import Enum
from typing import List, Union
from pushbullet import API

import customtkinter
import numpy as np
Expand All @@ -23,6 +24,8 @@
import utilities.imagesearch as imsearch
import utilities.ocr as ocr
import utilities.random_util as rd
import utilities.settings as settings

from utilities.geometry import Point, Rectangle
from utilities.mouse import Mouse
from utilities.options_builder import OptionsBuilder
Expand Down Expand Up @@ -84,6 +87,7 @@ class Bot(ABC):
progress: float = 0
status = BotStatus.STOPPED
thread: BotThread = None
pushbullet = API()

@abstractmethod
def __init__(self, game_title, bot_title, description, window: Window):
Expand Down Expand Up @@ -154,6 +158,8 @@ def play(self):
return
self.reset_progress()
self.set_status(BotStatus.RUNNING)
if settings.get("pushbullet_api_key"):
self.pushbullet.set_token(settings.get("pushbullet_api_key"))
self.thread = BotThread(target=self.main_loop)
self.thread.setDaemon(True)
self.thread.start()
Expand Down Expand Up @@ -596,3 +602,7 @@ def toggle_run(self, toggle_on: bool):
self.mouse.click()
else:
self.log_msg("Run is already off.")

def send_notification(self, title, body):
if settings.get("pushbullet_api_key"):
self.pushbullet.send_note(title, body)
13 changes: 13 additions & 0 deletions src/view/settings_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def __init__(self, parent):
)
widget_list.append(self.lbl_keybind_note)

# Pushbullet config
self.frame_pushbullet = customtkinter.CTkFrame(master=self)
self.frame_keybinds.columnconfigure(0, weight=0) # lbl label
self.frame_keybinds.columnconfigure(1, weight=1) # text input
self.pushbullet_label = customtkinter.CTkLabel(master=self.frame_pushbullet, text="Pushbullet API Key:")
self.pushbullet_label.grid(row=0, column=0)
self.pushbullet_widget = customtkinter.CTkEntry(master=self.frame_pushbullet, corner_radius=5, placeholder_text="Enter API Key...")
if settings.get("pushbullet_api_key"):
self.pushbullet_widget.insert(0, settings.get("pushbullet_api_key"))
self.pushbullet_widget.grid(row=0, column=1)
widget_list.append(self.frame_pushbullet)

# Grid layout
self.num_of_widgets = len(widget_list)
for i in range(self.num_of_widgets):
Expand Down Expand Up @@ -130,6 +142,7 @@ def save(self, window):
settings.set("keybind", settings.default_keybind)
print("No keybind set, using default keybind.")
settings.set("keybind", self.current_keys)
settings.set("pushbullet_api_key", self.pushbullet_widget.get().strip())
print(f"Keybind set to {settings.keybind_to_text(self.current_keys)}")
print("Please restart OSBC for changes to take effect.")
window.destroy()