Skip to content

Commit

Permalink
solve conflict in .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
derpicknicker1 committed Jan 10, 2017
2 parents d8ddf5f + 6615957 commit f5abdc6
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dist
*.zip
*.*~
*.yaml

dev_utils/NOTES.txt
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This plugin integrates Telegram Messenger with Octoprint. It sends messages (with photos if available) on print start, end and failure. Also it sends messages during the print at configurable intervals. That way you don't have to remember to regularly have a look at the printing process.
Also, you can control Octoprint via messages (settings, start a print and much more). Send `/status` to get the current printer status or `/abort` to abort the current print. Send `/help` for a list of all recognized commands. You may also use this bot in groups.

**Lates release: [1.4.0](https://github.com/fabianonline/OctoPrint-Telegram/releases)**
**Latest release: [1.4.2](https://github.com/fabianonline/OctoPrint-Telegram/releases)**

## Contents
* [Installation](#installation)
Expand Down Expand Up @@ -87,13 +87,13 @@ Congratulations! Your printer is now connected to your Telegram bot.<br><br><br>
1. Open your Octoprint settings and select *Telegram* on the left.


2. Send a start message (any message will do) to your new bot. You should receive a message from your bot which tells you something like "Now i know you".
2. Send a start message (any message will do) to your new bot. You should receive a message from your bot which tells you something like "Now I know you".


3. Now hit the "reload" button under the known chats list. The chat should appear in the list.


4. Save settings to accept new user(s)/group(s) in list
4. Save settings to accept new user(s)/group(s) in list.


5. Now reopen octoprit settings and check/set the configurations for new users. (see [below](#users))
Expand All @@ -103,6 +103,8 @@ Congratulations! Your printer is now connected to your Telegram bot.<br><br><br>
Configuration is done via the Octoprint settings dialog. Note that only admin users will be able to change user or token settings.

### General
**The paragraph numbers below correspond to the numbers in the picture!**

1. Token: Enter your bot token here. You got this from @botfather, when you [created](#create-telegram-bot) your bot there. *(admin users only)*


Expand All @@ -125,6 +127,8 @@ Configuration is done via the Octoprint settings dialog. Note that only admin us
### Users
There are users (private chat with single user) or groups you will see in the list of known chats. These settings are only accessible by admin users.

**The paragraph numbers below correspond to the numbers in the picture!**

1. When clicking the *command* icon, a dialog with a list of checkboxes for every accepted command will open. Check a box to enable the user/group to use the command. When done, close the dialog. Don't forget to enable general command execution in `3.`

2. By clicking on the *notification* icon, a dialog with a list of checkboxes for every known notification event will open. Checked notifications will be send to the user/group. When done, close the dialog. Don't forget to activate general notification in `3.`
Expand Down Expand Up @@ -159,6 +163,8 @@ There are users (private chat with single user) or groups you will see in the li
### Notifications
In this section you can configure the content of the notification messages.

**The paragraph numbers below correspond to the numbers in the picture!**

1. These three buttons will open dialogs which provide you informations about using markup, variables and emojis in the messages.

2. Enter the text you want to send when the specific event happens.
Expand Down Expand Up @@ -194,7 +200,7 @@ In this section you can configure the content of the notification messages.

**`/settings`** - Displays the current notification settings (time and height) and allows you to change them.

**`/files`** - Lists all the files available for printing in upload folder. No subdirectories are not listed. and lets you download and delete them. You also can view detailed informations of the file like print history.
**`/files`** - Lists all the files available for printing in upload folder and allows you download and delete them. You also can view detailed informations of the file like print history. If OctoPrint Version is >= 1.3.0, subdirectories are listed and you are able to move/copy files.

**`/print`** - Will open a file dialog showing the files stored in octoprint. You can select a file to print it.

Expand Down
25 changes: 16 additions & 9 deletions dev_utils/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### README
- /sys also system commands. Not only self defined
- Latest Version incement

### NOW
admin only settings

Expand All @@ -7,25 +11,18 @@

### CleanUp
css
! readme
code documentation

### Commands
delete/download files
File List multipage
message/icon/delay settings
[send video, makes no sense since telegram can't play .mpg]
user settings --> admin

### Features
SD-Card in Files
@uninstall:
- backup tracking token?
- del user images
combine _send_msg and _edit_send_msg
/files with folder representation?
- move files

save user settings in files
check webcam integration to hide/prevent "with image"
tab page with individual settings per print
Expand All @@ -38,7 +35,6 @@
admin user? --> admin
on "left_chat_member" dont delete --> deactivate
option to deactivate group chats if bot leaves a group to hold the settings if reentering --> deactivate
! gEmo() in message texts (.format(**locals()) to make settings send_icon work?
octoprint.util.repeated timer for notification time
check octoprint.util for useful things (dict!)

Expand All @@ -49,10 +45,21 @@
! after print start wait for nozzel and bed heated befor starting print notification
times are from octoprint so there has to be own counter??? :(

check systems.actions[].confirm when doing sysCommand
wrong image rotation


### Watchlist

TelegramAPI message Group objects (new_chat_icon, left_chat_member, etc.)
update user photos on startUp???
settings.save() on start user?
SD-Card in Files



hash 40
pathHash 8
page 2
opt 4
/files_ 7

99 changes: 90 additions & 9 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import
from PIL import Image
import threading, requests, re, time, datetime, StringIO, json, random, logging, traceback, io, collections, os, flask,base64,PIL
import threading, requests, re, time, datetime, StringIO, json, random, logging, traceback, io, collections, os, flask,base64,PIL, pkg_resources
import octoprint.plugin, octoprint.util, octoprint.filemanager
from flask.ext.babel import gettext
from flask.ext.login import current_user
Expand Down Expand Up @@ -164,7 +164,13 @@ def handleDocumentMessage(self, message, chat_id, from_id):
self.main.send_msg(self.gEmo('warning') + " Sorry, I only accept files with .gcode, .gco or .g extension.", chatID=chat_id)
raise ExitThisLoopException()
# download the file
target_filename = "telegram_" + file_name
if self.main.version >= 1.3:
target_filename = "TelegramPlugin/"+file_name
from octoprint.server.api.files import _verifyFolderExists
if not _verifyFolderExists(octoprint.filemanager.FileDestinations.LOCAL, "TelegramPlugin"):
self.main._file_manager.add_folder(octoprint.filemanager.FileDestinations.LOCAL,"TelegramPlugin")
else:
target_filename = "telegram_"+file_name
# for parameter no_markup see _send_edit_msg()
self.main.send_msg(self.gEmo('save') + gettext(" Saving file {}...".format(target_filename)), chatID=chat_id)
requests.get(self.main.bot_url + "/sendChatAction", params = {'chat_id': chat_id, 'action': 'upload_document'})
Expand Down Expand Up @@ -259,7 +265,7 @@ def parseUserData(self, message):
# send welcome message and skip message
if chat_id not in self.main.chats:
self.main.chats[chat_id] = data
self.main.send_msg(self.gEmo('info') + "Now i know you. Before you can do anything, go to OctoPrint Settings and edit some rights.",chatID=chat_id)
self.main.send_msg(self.gEmo('info') + "Now I know you. Before you can do anything, go to OctoPrint Settings and edit some rights.",chatID=chat_id)
kwargs = {'chat_id':int(chat_id)}
t = threading.Thread(target=self.main.get_usrPic, kwargs=kwargs)
t.daemon = True
Expand Down Expand Up @@ -347,7 +353,6 @@ class ExitThisLoopException(Exception):
############## THE PLUGIN ##############
########################################
########################################

class TelegramPlugin(octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SettingsPlugin,
octoprint.plugin.StartupPlugin,
Expand All @@ -357,7 +362,8 @@ class TelegramPlugin(octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.AssetPlugin
):

def __init__(self):
def __init__(self,version):
self.version = float(version)
# for more init stuff see on_after_startup()
self.thread = None
self.bot_url = None
Expand Down Expand Up @@ -402,7 +408,7 @@ def __init__(self):
'play': u'\U000025B6',
'stop': u'\U000025FC'
}
self.emojis.update(telegramEmojiDict)
self.emojis.update(telegramEmojiDict)
# all emojis will be get via this method to disable them globaly by the corrosponding setting
# so if you want to use emojis anywhere use gEmo("...") istead of emojis["..."]
def gEmo(self,key):
Expand Down Expand Up @@ -443,6 +449,19 @@ def get_template_configs(self):
dict(type="settings", name="Telegram", custom_bindings=True)
]

##########
### Wizard API
##########

def is_wizard_required(self):
return self._settings.get(["token"]) is ""

def get_wizard_version(self):
return 1
# Wizard version numbers used in releases
# < 1.4.2 : no settings versioning
# 1.4.2 : 1

##########
### Startup/Shutdown API
##########
Expand Down Expand Up @@ -506,6 +525,7 @@ def get_settings_version(self):
# 1.3.2 : 2
# 1.3.3 : 2
# 1.4.0 : 3
# 1.4.1 : 3

def get_settings_defaults(self):
return dict(
Expand All @@ -519,7 +539,8 @@ def get_settings_defaults(self):
chats = {'zBOTTOMOFCHATS':{'send_notifications': False,'accept_commands':False,'private':False}},
debug = False,
send_icon = True,
image_not_connected = True
image_not_connected = True,
fileOrder = False
)

def get_settings_preprocessors(self):
Expand Down Expand Up @@ -1123,7 +1144,7 @@ def take_image(self):
if flipH or flipV or rotate:
image = Image.open(StringIO.StringIO(data))
if rotate:
image = image.transpose(Image.ROTATE_90)
image = image.transpose(Image.ROTATE_270)
if flipH:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
if flipV:
Expand Down Expand Up @@ -1169,8 +1190,68 @@ def route_hook(self, server_routes, *args, **kwargs):
(r"/img/static/(.*)", LargeResponseHandler, dict(path=self._basefolder + "/static/img/", as_attachment=True,allow_client_caching =True))
]

########################################
########################################
### Some methods to check version and
### get the right implementation
########################################
########################################

# copied from pluginmanager plugin
def _is_octoprint_compatible(compatibility_entries):
"""
Tests if the current octoprint_version is compatible to any of the provided ``compatibility_entries``.
"""

octoprint_version = _get_octoprint_version()
for octo_compat in compatibility_entries:
if not any(octo_compat.startswith(c) for c in ("<", "<=", "!=", "==", ">=", ">", "~=", "===")):
octo_compat = ">={}".format(octo_compat)

s = next(pkg_resources.parse_requirements("OctoPrint" + octo_compat))
if octoprint_version in s:
break
else:
return False

return True

# copied from pluginmanager plugin
def _get_octoprint_version():
from octoprint.server import VERSION
octoprint_version_string = VERSION

if "-" in octoprint_version_string:
octoprint_version_string = octoprint_version_string[:octoprint_version_string.find("-")]

octoprint_version = pkg_resources.parse_version(octoprint_version_string)
if isinstance(octoprint_version, tuple):
# old setuptools
base_version = []
for part in octoprint_version:
if part.startswith("*"):
break
base_version.append(part)
octoprint_version = ".".join(base_version)
else:
# new setuptools
octoprint_version = pkg_resources.parse_version(octoprint_version.base_version)

return octoprint_version
# check if we have min version 1.3.0
# this is important because of WizardPlugin mixin and folders in filebrowser
def get_implementation_class():
if not _is_octoprint_compatible(["1.3.0"]):
return TelegramPlugin(1.2)
else:
class NewTelegramPlugin(TelegramPlugin,octoprint.plugin.WizardPlugin):
def __init__(self,version):
super(self.__class__, self).__init__(version)
return NewTelegramPlugin(1.3)


__plugin_name__ = "Telegram Notifications"
__plugin_implementation__ = TelegramPlugin()
__plugin_implementation__ = get_implementation_class()
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
"octoprint.server.http.routes": __plugin_implementation__.route_hook
Expand Down
6 changes: 5 additions & 1 deletion octoprint_telegram/static/js/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,14 @@ $(function() {
if(!response.ok){
$('#teleErrored').addClass("text-error");
$('#teleErrored').removeClass("text-success");
$('#teleErrored2').addClass("text-error");
$('#teleErrored2').removeClass("text-success");
}
else{
$('#teleErrored').addClass("text-success");
$('#teleErrored').removeClass("text-error");
$('#teleErrored2').addClass("text-success");
$('#teleErrored2').removeClass("text-error");
}

}
Expand Down Expand Up @@ -443,6 +447,6 @@ $(function() {
[ "settingsViewModel" ],

// e.g. #settings_plugin_telegram, #tab_plugin_telegram, ...
[ '#settings_plugin_telegram' ]
[ '#settings_plugin_telegram','#wizard_plugin_telegram']
]);
});
Loading

0 comments on commit f5abdc6

Please sign in to comment.