Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #34 from TimJentzsch/master
Browse files Browse the repository at this point in the history
Add /help and /info as proposed in #26 and #31
Remove invalid subscribers as proposed in #24
  • Loading branch information
zachkont authored Nov 15, 2017
2 parents 9ecc195 + 2bb7157 commit c070ede
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
27 changes: 25 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import logging
import telebot
import requests
import feedparser
import dota2api
Expand All @@ -16,10 +16,33 @@
heroes_list = heroes_list["heroes"]


@bot.message_handler(commands=['start', 'help'])
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")

@bot.message_handler(commands=['help'])
def get_help(message):
gitUrl = "https://github.com/zachkont/dotaUpdatesBot"
redditUrl = "https://www.reddit.com/message/compose/?to=karaflix"
bot.reply_to(message,
u'Did you find a bug or have any questions?\n'
+ u'Visit the [GitHub page]({gitUrl})'.format(gitUrl=gitUrl)
+ u' for more information or contact'
+ u' [/u/karaflix]({redditUrl})'.format(redditUrl=redditUrl)
+ u' on reddit!',
parse_mode="Markdown",
disable_web_page_preview=True)

@bot.message_handler(commands=['info'])
def get_info(message):
gitUrl = "https://github.com/zachkont/dotaUpdatesBot"
bot.reply_to(message,
u'The main use of this bot is to notify you whenever a Dota update gets released.\n'
+ u'Visit the [GitHub page]({gitUrl})'.format(gitUrl=gitUrl)
+ u' for more information on what you can do or how to contribute!',
parse_mode="Markdown",
disable_web_page_preview=True)


@bot.message_handler(commands=['dotanews', 'dotanew', 'dnews', 'dnew'])
def dota_news(message):
Expand Down
20 changes: 18 additions & 2 deletions updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import json
import time
import sys
import feedparser
import telebot

from bs4 import BeautifulSoup
from datetime import datetime

from utils import bot, loadjson, addBlogPostInstantView
import sys
from utils import bot, loadjson, deljson, addBlogPostInstantView

reload(sys)
sys.setdefaultencoding('utf-8')
Expand Down Expand Up @@ -84,6 +84,14 @@ def notify_users_and_groups(message):
for user_id in loadjson("userlist"):
try:
bot.send_message(user_id, message, parse_mode="Markdown")
except telebot.apihelper.ApiException as ex:
USER_BLOCK_ERROR = "Forbidden: bot was blocked by the user"
if(USER_BLOCK_ERROR in str(ex)):
print("{date}: The user {user_id} has blocked the bot. The user will be removed.".format(date=datetime.now(), user_id=user_id), file=log)
deljson(user_id, "userlist")
else:
telebot.logger.error(ex)
print("{}: Message could not be sent to group - Telebot API Error".format(datetime.now()), file=log)
except Exception as ex:
telebot.logger.error(ex)
print("{}: Message could not be sent to users".format(datetime.now()), file=log)
Expand All @@ -92,6 +100,14 @@ def notify_users_and_groups(message):
for gid in loadjson("grouplist").keys():
try:
bot.send_message(gid, message, parse_mode="Markdown")
except telebot.apihelper.ApiException as ex:
GROUP_BLOCK_ERROR = "Forbidden: bot was kicked from the group chat"
if(GROUP_BLOCK_ERROR in str(ex)):
print("{date}: The group {gid} has kicked the bot. The group will be removed.".format(date=datetime.now(), gid=gid), file=log)
deljson(gid, "grouplist")
else:
telebot.logger.error(ex)
print("{}: Message could not be sent to group - Telebot API Error".format(datetime.now()), file=log)
except Exception as ex:
telebot.logger.error(ex)
print("{}: Message could not be sent to groups".format(datetime.now()), file=log)
Expand Down

0 comments on commit c070ede

Please sign in to comment.