Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf8
- from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
- ConversationHandler, StringCommandHandler, Dispatcher)
- from telegram.ext.dispatcher import run_async
- from telegram import MessageEntity, ChatAction
- from random import randint
- import logging
- import csv
- import re
- import sys
- import time
- import traceback
- # locale.setlocale(locale.LC_ALL,"de_DE")
- reload(sys)
- sys.setdefaultencoding('utf8')
- # Enable logging
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
- level=logging.INFO)
- logger = logging.getLogger(__name__)
- def start(bot, update):
- update.message.reply_text(
- 'Hallo! Hier ist Butler Murphy und ich kann dir helfen, wenn du mir ein Befehl schickst.\n'
- 'Frage mich nach der Liste mit #liste und du bekommst alle möglichen Befehle aufgelistet.\n')
- @run_async
- def doSleepDel(bot, update, send, sleeptime, kind):
- # print(bot)
- # print(update)
- # print(send)
- # print(sleeptime)
- # print(kind)
- # print(type(send))
- try:
- # if update.effective_chat.type == 'private':
- # if kind == 1:
- # bot.send_message(chat_id=update.message.chat_id, text=send, parse_mode='Markdown', disable_web_page_preview=True)
- # #update.message.reply_text(send, parse_mode='Markdown', disable_web_page_preview=True)
- # elif kind == 2:
- # bot.send_photo(chat_id=update.message.chat_id, photo=open(send, 'rb'))
- # #update.message.reply_photo(photo=open(send, 'rb'))
- if kind == 1:
- bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING, timeout=5)
- send = update.message.reply_text(send, timeout=5, parse_mode='Markdown', disable_web_page_preview=True)
- elif kind == 2:
- bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.UPLOAD_PHOTO, timeout=10)
- send = update.message.reply_photo(photo=open(send, 'rb'), timeout=10, UPLOAD_PHOTO = 'upload_photo')
- if update.effective_chat.type == 'supergroup':
- time.sleep(sleeptime)
- bot.delete_message(chat_id=update.message.chat_id, message_id=send['reply_to_message']['message_id'])
- bot.delete_message(chat_id=update.message.chat_id, message_id=send['message_id'])
- except:
- traceback.print_exc()
- print("Exception")
- doSleepDel(bot, update, send, 20, 1)
- # if kind == 1:
- # send = update.message.reply_text(send, parse_mode='Markdown', disable_web_page_preview=True)
- # elif kind == 2:
- # send = update.message.reply_photo(photo=open(send, 'rb'))
- # if not update.effective_chat.kind == 'private':
- # time.sleep(sleeptime)
- # bot.delete_message(chat_id=update.message.chat_id, message_id=send['reply_to_message']['message_id'])
- # bot.delete_message(chat_id=update.message.chat_id, message_id=send['message_id'])
- @run_async
- def hashtag(bot, update):
- logger.info("Mitglied: %s; Eingabe: %s", update.message.from_user.first_name, update.message.text)
- hashtag = update.message.text.lower().split()[0]
- if '#' in hashtag: #Muss sein, da sonst im gesamten Text nach Hashtags gesucht wird.
- if '#adblue' == hashtag:
- send = "[AdBlue Zapfsäulen](http://goo.gl/4i5opM)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#bahn' == hashtag:
- send = ("[Hauptbahnhof](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BL&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BL&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0)\n"
- "[Ostbahnhof](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BHF&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BHF&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0)\n"
- "[Bf Gesundbrunnen](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BGS&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BGS&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0)\n"
- "[Bf Südkreuz](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BPAF&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BPAF&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0)\n"
- "[Bf Spandau](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BSPD&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BSPD&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=1)\n"
- "[Bf Zoo](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BZOO&zugtyp=&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0);"
- "[Nur ICE](https://iris.noncd.db.de/wbt/js/index.html?typ=an&bhf=BZOO&zugtyp=ICE&platform=&bhfname=&style=an&via=0&impressum=0&lang=de&SecLang=&zeilen=17&paging=&pagingdauer=&impressum=0)")
- doSleepDel(bot, update, send, 60, 1)
- elif '#bordell' == hashtag:
- send = "[Karte mit Bordellen](https://goo.gl/hn4vYQ)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#cash' == hashtag:
- send = "[Karte mit Geldautomaten](https://finde.cash/)"
- doSleepDel(bot, update, send, 20, 1)
- elif '#clubs' == hashtag:
- send = ("*Clublisten:*\n"
- "[RA Guide](https://www.residentadvisor.net/events)\n"
- "[Blout!](http://blout.appyo.de/)\n"
- "[Gästeliste030](https://www.gaesteliste030.de/)\n"
- "[Virtual Nights](https://www.virtualnights.com/berlin/events)")
- doSleepDel(bot, update, send, 60, 1)
- elif '#dbfahrt' == hashtag:
- try:
- km = float(update.message.text.lower().split()[1].replace(',','.'))
- euroProKm4 = 0.87
- euroProKm5 = 1
- erg4 = 2*km*euroProKm4
- erg5 = 2*km*euroProKm5
- send = ("Die {} km lange Fahrt würde kosten:\n"
- "*Mit max. 4 Personen:*\n Netto: {:.2f} €\n Brutto: {:.2f} €\n"
- "*Mit über 5 Personen:*\n Netto: {:.2f} €\n Brutto: {:.2f} €"
- .format(mN(km), mN(erg4), mN(erg4*1.19), mN(erg5), mN(erg5*1.19)))
- doSleepDel(bot, update, send, 60, 1)
- except:
- traceback.print_exc()
- send = "Entweder fehlt die Anzahl der Kilometer oder die Eingabe ist ungültig."
- doSleepDel(bot, update, send, 10, 1)
- elif '#fashion' == hashtag:
- send = "[Fashion Week Kalender](https://t.co/RGxOflosJf?ssr=true)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#funk' == hashtag:
- send = "[Funk Taxi Berlin (WBT)](https://m.taxi4me.net/mobile/index2.html?z=2620)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#hbf' == hashtag:
- send = "#hbf wurde durch #bahn ersetzt."
- doSleepDel(bot, update, send, 10, 1)
- elif '#hp' == hashtag:
- send = "[Karte mit Taxi-Halteplätzen](https://goo.gl/VXngKZ)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#kotze' == hashtag:
- send = 'kotze.jpg'
- doSleepDel(bot, update, send, 60, 2)
- elif '#links' == hashtag:
- send = ("*Taxi Gruppe Berlin:*\n"
- "_(Nur arbeitsbezogene Meldungen und Fragen.)_"
- "\t [https://t.me/joinchat/Ftnlv08gvnQmzDEVtfHcsA](https://t.me/joinchat/Ftnlv08gvnQmzDEVtfHcsA)\n\n"
- "*TGB Verkehr:*\n"
- "_(Nur Verkehrsbezogene Meldungen und Fragen.)_\t"
- "[https://t.me/joinchat/Ftnlv0pyBjqQlz7Fk_Ic-A](https://t.me/joinchat/Ftnlv0pyBjqQlz7Fk_Ic-A)\n\n"
- "*TGB Lobby:*\n"
- "_(Sonstige Fragen, SMALLtalk, Dialog mit Taxifahrern.)_\t"
- "[https://t.me/joinchat/Ftnlv02oVBIF7NC6Y_CWVw](https://t.me/joinchat/Ftnlv02oVBIF7NC6Y_CWVw)")
- doSleepDel(bot, update, send, 60, 1)
- elif '#liste' == hashtag:
- send = ("*Liste aller Hashtags:*\n\n"
- "#adblue: Tankstellenkarte mit AdBlue Zapfsäulen.\n"
- "#bahn: Ankunftszeiten an Bahnhöfen.\n"
- "#bordell: Karte mit Bordellen.\n"
- "#cash: Karte mit Bankautomaten.\n"
- "#clubs: Links von 4 Clubseiten.\n"
- "#dbfahrt: Fahrtkostenrechner für DB Fahrten."
- "#fashion: Fashion Week Kalender\n"
- "#funk: Taxi Bestellung über Funk Taxi Berlin (WBT)\n"
- "#hp: Karte mit Taxi-Halteplätzen.\n"
- "#kotze: Zeigt eine Liste mit Gebühren für ein vollgekotztes Taxi.\n"
- "#links: Gruppenlinks\n"
- "#liste: Diese Hashtagliste.\n"
- "#messe: Aktuelle Messen.\n"
- "#messeplan: Lageplan der Messe.\n"
- "#mytaxi: Link der MyTaxi Fahrerapp.\n"
- "#persius: Link der Taxi Berlin Fahrerapp.\n"
- "#preis: Fahrtkostenrechner.\n"
- "#qp: QPark TXL Öffnungszeiten und Tel.-Nr.\n"
- "#qr: QR-Code der Gruppe, zum schnellen teilen des Links.\n"
- "#sektor: Zeigt den Sektornamen zur Sektornummer. Eingabe: #sektor \[Nr.]\n"
- "#sp: 24/7 Spätkäufe.\n"
- "#taxi: Taxi Bestellung über Taxi Berlin.\n"
- "#tr: Fahrtkostenechner per Google Maps.\n"
- "#txl: TXL Ankünfte.\n"
- "#wasch: 24/7 Waschanlagen.\n"
- "#wc: Karte mit Toiletten.\n"
- "#zob: ZOB Ankünfte.")
- doSleepDel(bot, update, send, 60, 1)
- elif '#messe' == hashtag:
- send = "[Aktuelle Messen](https://rbbtext.mobi/597)"
- doSleepDel(bot, update, send, 40, 1)
- elif '#messeplan' == hashtag:
- send = 'messeplan.jpg'
- doSleepDel(bot, update, send, 40, 2)
- elif '#mytaxi' == hashtag:
- send = "[MyTaxi Fahrerapp](https://d.mytaxi.com/)\n 24/7 Rufnummer: +49 171 7631803"
- doSleepDel(bot, update, send, 10, 1)
- elif '#persius' == hashtag:
- send = "[Taxi Berlin Fahrerapp (Android)](http://www.taxi.eu/fahrerapp)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#preis' == hashtag:
- try:
- km = float(update.message.text.lower().split()[1].replace(',','.'))
- if 0 < km < 50:
- if km <= 7:
- send = "Die Fahrt würde ungefähr {}€ kosten.".format(format_number_0b(3.90+(2*km)))
- elif km >7:
- send = "Die Fahrt würde ungefähr {}€ kosten.".format(format_number_0b(7.40+(km * 1.5)))
- elif km >=50:
- send = ("Die Fahrt würde ungefähr {}€ kosten.\n"
- "Es scheint sich um eine Umland-\Fernfahrt zu handeln. In diesem Falle solltest du {}€ verlangen."
- .format(format_number_0b(7.40+(km * 1.5)), format_number_0b(3.90+(2*km))))
- else:
- send = "Gib eine Zahl größer als 0 ein."
- doSleepDel(bot, update, send, 20, 1)
- except:
- traceback.print_exc()
- send = "Entweder fehlt die Anzahl der Kilometer oder die Eingabe ist ungültig."
- doSleepDel(bot, update, send, 10, 1)
- elif '#qp' == hashtag:
- send = "*QPark TXL TP-Verkaufszeiten:*\n Mo.: 14-16 Uhr/Do.: 20-12 Uhr\n Sollte niemand im Büro sein: 0151 440 394 06"
- doSleepDel(bot, update, send, 40, 1)
- elif '#qr' == hashtag:
- send = "Sende QR Code"
- elif '#sektor' == hashtag:
- try:
- sektornummer = int(update.message.text.lower().split()[1])
- with open('SEKTOR.csv') as csvDataFile:
- csvReader = csv.reader(csvDataFile, delimiter=';')
- erg = ''
- for row in csvReader:
- if re.match(str(sektornummer) + '$', row[0]):
- print(row[1])
- erg = row[1]
- if erg == '':
- send = "Dazu gibt es keinen Sektor. Deine Eingabe war: {}.".format(update.message.text)
- else:
- send = "Die Nummer {} hat den Sektornamen {}.".format(sektornummer, erg)
- doSleepDel(bot, update, send, 20, 1)
- except:
- traceback.print_exc()
- send = "Fehler. Versuche es noch einmal. Eingabe war: {}\nKorrekte Syntax: #sektor \[Nr.]".format(update.message.text)
- doSleepDel(bot, update, send, 10, 1)
- elif '#sp' == hashtag:
- send = "[24/7 Spätkäufe](https://goo.gl/JpWr4g)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#taxi' == hashtag:
- send = "[Taxi Berlin Bestellung](https://m.taxi4me.net/mobile/index2.html?z=2020#/)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#tr' == hashtag:
- send = "[Taxirechner](http://www.taxi-rechner.de/)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#txl' == hashtag:
- send = "[TXL Ankünfte](http://www.berlin-airport.de/de/reisende-txl/ankuenfte-und-abfluege/ankuenfte/index.php)"
- doSleepDel(bot, update, send, 40, 1)
- elif '#wasch' == hashtag:
- send = "[24/7 Waschanlagen](https://goo.gl/RC211s)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#wc' == hashtag:
- send = "[Karte mit Toiletten](https://goo.gl/HS7ZpW)"
- doSleepDel(bot, update, send, 10, 1)
- elif '#zob' == hashtag:
- send = "[ZOB Ankünfte](http://zob.berlin/de/fahrgaeste-und-besucher#ankuenfte)"
- doSleepDel(bot, update, send, 30, 1)
- else:
- send = "Diesen Befehl kenne ich nicht. Die #liste zeigt alle vorhandenen Befehle."
- doSleepDel(bot, update, send, 15, 1)
- def format_number_0b(number,format="%0.2f",comma=",",thousand=".",grouplength=3):
- if abs(number) < 10**grouplength:
- if type(number) is str:
- if number == '':
- number = 0
- f = float(number)
- if f.is_integer():
- return int(f)
- else:
- return (format % (number)).replace(".", comma)
- if format[-1]=="f":
- vor_komma,hinter_komma=(format % number).split(".",-1)
- else:
- vor_komma=format % number
- comma=""
- hinter_komma=""
- #Hier
- anz_leer=0
- for i in vor_komma:
- if i==" ":
- anz_leer+=1
- else:
- break
- vor_komma=vor_komma[anz_leer:]
- #bis hier
- len_vor_komma=len(vor_komma)
- for i in range(grouplength,len_vor_komma+(len_vor_komma-1)/(grouplength+1)-(number<0),grouplength+1):
- vor_komma=vor_komma[0:-(i)]+thousand+vor_komma[-(i):]
- if hinter_komma == '00':
- return anz_leer*" "+vor_komma
- else:
- return anz_leer*" "+vor_komma+comma+hinter_komma
- def mN(x):
- if type(x) is str:
- if x == '':
- x = 0
- f = float(x)
- if f.is_integer():
- return int(f)
- else:
- return f
- def error(bot, update, error):
- """Log Errors caused by Updates."""
- logger.warning('Update "%s" caused error "%s"', update, error)
- # def filter_chat_id(message):
- # return message.chat_id not in allowed_chat_ids Filters.chat(-1001302877202),
- def main():
- # Create the EventHandler and pass it your bot's token.
- updater = Updater("x")
- # Get the dispatcher to register handlers
- updater.dispatcher.add_handler(CommandHandler('start', start))
- updater.dispatcher.add_handler(MessageHandler(Filters.text & Filters.entity('hashtag'), hashtag))
- # log all errors
- updater.dispatcher.add_error_handler(error)
- # Start the Bot
- updater.start_polling(poll_interval = 1.5
- , timeout=5)
- # Run the bot until you press Ctrl-C or the process receives SIGINT,
- # SIGTERM or SIGABRT. This should be used most of the time, since
- # start_polling() is non-blocking and will stop the bot gracefully.
- updater.idle()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement