diff --git a/game_manager.py b/game_manager.py
index 4be3bc75..23d8426f 100644
--- a/game_manager.py
+++ b/game_manager.py
@@ -24,7 +24,7 @@
from player import Player
from errors import (AlreadyJoinedError, LobbyClosedError, NoGameInChatError,
NotEnoughPlayersError)
-
+from promotions import send_promotion_async
class GameManager(object):
""" Manages all running games by using a confusing amount of dicts """
@@ -143,6 +143,7 @@ def end_game(self, chat, user):
"""
self.logger.info("Game in chat " + str(chat.id) + " ended")
+ send_promotion_async(chat, chance=0.15)
# Find the correct game instance to end
player = self.player_for_user_in_chat(user, chat)
diff --git a/promotions.py b/promotions.py
new file mode 100644
index 00000000..967055d1
--- /dev/null
+++ b/promotions.py
@@ -0,0 +1,34 @@
+"""
+Promote other UNO bots
+"""
+import random
+
+
+# Promotion messages and their weights
+PROMOTIONS = {
+ """
+For a more modern UNO experience, try out the new @uno9bot.
+""": 2.0,
+ """
+Also check out @UnoDemoBot, a newer version of this bot with exclusive modes and features!
+""": 1.0,
+}
+
+def get_promotion():
+ """ Get a random promotion message """
+ return random.choices(list(PROMOTIONS.keys()), weights=list(PROMOTIONS.values()))[0]
+
+def send_promotion(chat, chance=1.0):
+ """ (Maybe) send a promotion message """
+ if random.random() <= chance:
+ chat.send_message(get_promotion(), parse_mode='HTML')
+
+
+def send_promotion_async(chat, chance=1.0):
+ """ Send a promotion message asynchronously """
+
+ from utils import dispatcher, error
+ try:
+ dispatcher.run_async(send_promotion, chat, chance=chance)
+ except Exception as e:
+ error(None, None, e)
diff --git a/simple_commands.py b/simple_commands.py
index 62ffd2de..5720793b 100644
--- a/simple_commands.py
+++ b/simple_commands.py
@@ -24,6 +24,7 @@
from utils import send_async
from shared_vars import dispatcher
from internationalization import _, user_locale
+from promotions import send_promotion
@user_locale
def help_handler(update: Update, context: CallbackContext):
@@ -64,8 +65,15 @@ def help_handler(update: Update, context: CallbackContext):
"update channel"
" and buy an UNO card game.")
- send_async(context.bot, update.message.chat_id, text=help_text,
- parse_mode=ParseMode.HTML, disable_web_page_preview=True)
+ def _send():
+ update.message.chat.send_message(
+ help_text,
+ parse_mode=ParseMode.HTML,
+ disable_web_page_preview=True,
+ )
+ send_promotion(update.effective_chat)
+
+ context.dispatcher.run_async(_send)
@user_locale
def modes(update: Update, context: CallbackContext):