bot.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pubg_lablab
  2. from uuid import uuid4
  3. from telegram.ext import MessageHandler, Filters, Updater, InlineQueryHandler
  4. from telegram import InlineQueryResultArticle, InputTextMessageContent, ParseMode
  5. bg = pubg_lablab.Battlegrounds('Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI1NzdjYzFlMC1jM2UwLTAxMzYtOWJiZS02YjYxOGIyZjU5NzQiLCJpc3MiOiJnYW1lbG9ja2VyIiwiaWF0IjoxNTQxNTAxNzA1LCJwdWIiOiJibHVlaG9sZSIsInRpdGxlIjoicHViZyIsImFwcCI6InB1YmdfdGVsZWdyYW0ifQ.yANNOqbPTDA0aBxMvriJ35c6Fg2b2g7JC9esndsXKOg', 'pc_eu')
  6. def bot_query(bot, update):
  7. query = update.inline_query.query
  8. print(query)
  9. allowed_users = ['Vogelstrauss', 'tsi_tsi', 'Ceelbee', 'Konfusio']
  10. if query in allowed_users:
  11. squad_lifetime_stats = bg.lifetime(bg.player(query).id).squad
  12. out = query + " (Rounds: " + str(squad_lifetime_stats.roundsPlayed) + ")" \
  13. + "\nKills: " + str(squad_lifetime_stats.kills) \
  14. + "\nHeadshot Kills: " + str(squad_lifetime_stats.headshotKills) \
  15. + "\nAssists: " + str(squad_lifetime_stats.assists) \
  16. + "\nRoad Kills: " + str(squad_lifetime_stats.roadKills) \
  17. + "\nLongest Shot: " + str(squad_lifetime_stats.longestKill)
  18. options = [
  19. InlineQueryResultArticle(
  20. id=uuid4(),
  21. title="Total Kills",
  22. input_message_content=InputTextMessageContent(out , parse_mode = "HTML"))
  23. ]
  24. print(options)
  25. if query == 'rank':
  26. toplist = {}
  27. for i in allowed_users:
  28. stats = bg.lifetime(bg.player(i).id).squad
  29. toplist[i] = stats.kills
  30. toplist = sorted(toplist.items(), key=lambda kv: kv[1], reverse=True)
  31. out = "Ranking\n"
  32. n = 1
  33. for i in toplist:
  34. out += str(n) + ". " + str(i[0]) + " - " + str(i[1]) + '\n'
  35. n = n + 1
  36. options = [
  37. InlineQueryResultArticle(
  38. id=uuid4(),
  39. title="Ranking",
  40. input_message_content=InputTextMessageContent(out , parse_mode = "HTML"))
  41. ]
  42. update.inline_query.answer(options, cache_time=0)
  43. updater = Updater(token='627697353:AAEuYCZSPfMg9ll0D0Gf3QhA9G21wJh97Wk')
  44. dispatcher = updater.dispatcher
  45. dispatcher.add_handler(InlineQueryHandler(bot_query))
  46. updater.start_polling(clean=True)
  47. print ("Running")
  48. updater.idle()