forked from JungDev/django-telegrambot
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for python-telegram-bot release v6.0.1, and more
- Loading branch information
Showing
9 changed files
with
310 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = '0.2.6' | ||
__version__ = '0.2.7' | ||
default_app_config = 'django_telegrambot.apps.DjangoTelegramBot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
#from telegram.ext import Updater | ||
|
||
from django_telegrambot.apps import DjangoTelegramBot | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Run telegram bot in polling mode" | ||
can_import_settings = True | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--username', '-i', help="Bot username", default=None) | ||
parser.add_argument('--token', '-t', help="Bot token", default=None) | ||
pass | ||
|
||
def get_updater(self, username=None, token=None): | ||
updater = None | ||
if username is not None: | ||
updater = DjangoTelegramBot.get_updater(bot_id=username) | ||
if not updater: | ||
self.stderr.write("Cannot find default bot with username {}".format(username)) | ||
elif token: | ||
updater = DjangoTelegramBot.get_updater(bot_id=token) | ||
if not updater: | ||
self.stderr.write("Cannot find bot with token {}".format(token)) | ||
return updater | ||
|
||
def handle(self, *args, **options): | ||
from django.conf import settings | ||
if not settings.TELEGRAM_BOT_MODE == 'POLLING': | ||
self.stderr.write("Webhook mode active, change it in your settings if you want use polling update") | ||
return | ||
|
||
updater = self.get_updater(username=options.get('username'), token=options.get('token')) | ||
if not updater: | ||
self.stderr.write("Bot not found") | ||
return | ||
# Enable Logging | ||
logging.basicConfig( | ||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | ||
level=logging.INFO) | ||
logger = logging.getLogger("telegrambot") | ||
logger.setLevel(logging.INFO) | ||
console = logging.StreamHandler() | ||
console.setLevel(logging.INFO) | ||
console.setFormatter(logging.Formatter('%(name)s - %(levelname)s - %(message)s')) | ||
logger.addHandler(console) | ||
|
||
#wbinfo = updater.bot.getWebhookInfo() | ||
#logger.warn(wbinfo) | ||
#updater.bot.deleteWebhook() #not yet present in python-telegram-bot 5.3.1 | ||
self.stdout.write("Run polling...") | ||
updater.start_polling() | ||
self.stdout.write("the bot is started and runs until we press Ctrl-C on the command line.") | ||
updater.idle() |
88 changes: 88 additions & 0 deletions
88
django_telegrambot/templates/django_telegrambot/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{% extends "admin/index.html" %} | ||
{% block extrastyle %} | ||
{{ block.super }} | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | ||
<style> | ||
#django-telegrambot ul li { | ||
list-style-type: none; | ||
} | ||
ul.nolist{ | ||
margin-left: 10px; | ||
padding-left: 0; | ||
} | ||
.dodgerblue{ | ||
color: dodgerblue; | ||
} | ||
.botlist{ | ||
font-size: 1.5em; | ||
} | ||
#django-telegrambot li {font-size: 1.1em;} | ||
</style> | ||
{% endblock %} | ||
{% block extrahead %} | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.6.1/clipboard.min.js"></script> | ||
|
||
<script src="https://use.fontawesome.com/c8dc42a356.js"></script> | ||
<script> | ||
$( document ).ready(function() { | ||
|
||
var clipboard = new Clipboard('.btn'); | ||
clipboard.on('success', function(e) { | ||
e.clearSelection(); | ||
}); | ||
|
||
clipboard.on('error', function(e) { | ||
console.error('Action:', e.action); | ||
console.error('Trigger:', e.trigger); | ||
}); | ||
}); | ||
</script> | ||
{% endblock %} | ||
{% block breadcrumbs %} | ||
<div class="breadcrumbs"> | ||
<a href="{% url 'admin:index' %}">Home</a> › | ||
<a href="{% url 'django-telegrambot' %}">Django Telegrambot</a> | ||
</div> | ||
{% endblock %} | ||
{% block content %} | ||
|
||
|
||
{{ block.super }} | ||
<div id = 'django-telegrambot' style = "float: left"> | ||
<h1><a href="https://github.com/JungDev/django-telegrambot#django-telegrambot">Django-TelegramBot</a></h1> | ||
<p> | ||
The full documentation is at <a href="https://django-telegrambot.readthedocs.org">https://django-telegrambot.readthedocs.org</a>. | ||
</p> | ||
<h3>Bot update mode: <b>{{update_mode}}</b></h3> | ||
{% if update_mode == 'POLLING' %}<p>Please remember to start polling mode with commands: | ||
<ul class="nolist"> | ||
{% for bot in bot_list %} | ||
<li> | ||
<kbd>$ python manage.py botpolling --username={{bot.username}}</kbd> | ||
<button class="btn btn-default btn-xs" data-clipboard-text="python manage.py botpolling --username={{bot.username}}"> | ||
<i class="fa fa-clipboard" aria-hidden="true"></i> | ||
</button> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</p> | ||
{% endif %} | ||
|
||
{% if bot_list %} | ||
<h3>Bot List:</h3> | ||
<ul class="nolist botlist"> | ||
{% for bot in bot_list %} | ||
<i class="fa fa-telegram dodgerblue" aria-hidden="true"></i> | ||
<b>{{ bot.first_name}}</b> | ||
<a class="btn btn-default btn-sm" href="https://t.me/{{ bot.username }}/?start=true" role="button" title="start a chat">@{{ bot.username}}</a> | ||
<a class="btn btn-default btn-sm" href="https://t.me/{{ bot.username }}/?startgroup=true" role="button">Add to group/channel</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<p>No bots are available. Please <a href="https://github.com/JungDev/django-telegrambot#configure-your-installation">configure it</a> in settings.py</p> | ||
{% endif %} | ||
</div> | ||
|
||
{% endblock %} |
Oops, something went wrong.