Skip to content

Commit

Permalink
Add whobets
Browse files Browse the repository at this point in the history
  • Loading branch information
boomhq committed May 24, 2020
1 parent 46f2784 commit 3fc838c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 20 deletions.
27 changes: 15 additions & 12 deletions Models/betMODEL.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, relationship, lazyload, subqueryload, lazyload_all, subqueryload_all, joinedload
from sqlalchemy import create_engine

Base = declarative_base()
Expand Down Expand Up @@ -37,34 +37,37 @@ class Ranking(Base):
total = Column(Integer, default=0)


class Bet(Base):
__tablename__ = "bets"
class User(Base):
__tablename__ = "users"
__table_args__ = {
"mysql_engine": "InnoDB",
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
player_id = Column(Integer)
match = Column(Integer)
bet = Column(String(50))
player_id = Column(Integer, unique=True)
bets = relationship("Bet", back_populates="player")
telegram = Column(String(191))
notify = Column(Integer)


class User(Base):
__tablename__ = "users"
class Bet(Base):
__tablename__ = "bets"
__table_args__ = {
"mysql_engine": "InnoDB",
"mysql_charset": "utf8mb4",
"mysql_collate": "utf8mb4_unicode_ci",
}
id = Column(Integer, primary_key=True)
player_id = Column(Integer)
telegram = Column(String(191))
notify = Column(Integer)
player_id = Column(Integer, ForeignKey("users.player_id"))
player = relationship("User", back_populates="bets")
match = Column(Integer)
bet = Column(String(50))


schema = os.environ.get("BET_BOT_SCHEMA")
engine = create_engine(schema)

Base.metadata.create_all(engine)

DBSession = sessionmaker(bind=engine)
Expand Down
22 changes: 17 additions & 5 deletions Modules/ListMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
def list_bets(message):
query = get_matches()
matches = query.filter(Match.score1 == None).all()
text = ""
text = (
"*************************"
+ " \n"
+ _("Faites /bet pour vous positionnez sur un match")
+ " \n"
+ _("Faites /whobets pour voir les positions des autres personnes")
+ " \n"
+ "*************************"
+ " \n"
)
query = get_bets()
for m in matches:
bets = query.filter(Bet.match == m.id).all()
Expand All @@ -22,16 +31,18 @@ def list_bets(message):
odd2 = bets2 * 100 / (bets1 + bets2)
text += (
" *"
+ "========================="
+ "\n"
+ m.title
+ "* "
+ "\n"
+ emoji(":calendar:")
+ _('Fin de la prise des paris')
+ date
+ " "
+ emoji(":clock1:")
+ _('at')
+ hour
+ " "
+ emoji(" :fast_forward:")
+ "\n"
+ " *"
+ m.team1
+ "* "
Expand All @@ -44,9 +55,10 @@ def list_bets(message):
+ "% *"
+ m.team2
+ "\n"
+ "========================="
+ "*\n"
)
if not matches:
bot.send_message(message.chat.id, _("No matches available."))
else:
bot.send_message(message.chat.id, text, parse_mode="markdown")
bot.send_message(message.chat.id, text, parse_mode="markdown")
47 changes: 47 additions & 0 deletions Modules/WhoBets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@bot.message_handler(commands=["whobets", "whobet"])
def who_bet(message):
if message.chat.type != "private":
bot.send_message(
message.chat.id, _("This command can not be used on group chats.")
)
return
chat_id = message.chat.id
query = get_matches()
matches = query.filter(Match.score1 == None).filter(Match.score1 == None).all()
if not matches:
bot.send_message(message.chat.id, _("No matches available."))
return
markup = types.ReplyKeyboardMarkup(row_width=len(matches))
for m in matches:
markup.add(str(m.id) + " - " + m.title + " - " + m.team1 + " - " + m.team2)
markup.add(_("Cancel"))
bot.send_message(chat_id, _("Choose a match:"), reply_markup=markup)
userStep[message.from_user.id] = 100


@bot.message_handler(func=lambda message: get_user_step(message.from_user.id) == 100)
def confirm_match_choose(message):
if message.text == _("Cancel"):
markup = types.ReplyKeyboardRemove()
bot.send_message(message.chat.id, _("Action cancelled."), reply_markup=markup)
userStep[message.from_user.id] = None
return

chat_id = message.chat.id
markup = types.ReplyKeyboardRemove()

bot.send_message(chat_id, _("Voici les paris enregistre pour ce match"), reply_markup=markup)

mid = message.text.split(" ")
queryMatch = get_matches()
match = queryMatch.filter(Match.id == int(mid[0])).one()

queryBets = get_bets()
bets = queryBets.filter(Bet.match == int(mid[0])).options(joinedload('player')).all()
text = ""
for bet in bets:
text += "Pseudo : * "+bet.player.telegram+" * Choix : *" + bet.bet + " *\n"

markup = types.ReplyKeyboardRemove()
bot.send_message(chat_id, text, reply_markup=markup, parse_mode="markdown")
userStep[message.from_user.id] = None
3 changes: 2 additions & 1 deletion Settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
path = os.path.dirname(os.path.abspath(__file__))
enabled_modules = [
"Helpers",
"Users",
"AddMatch",
"Bet",
"DeleteMatch",
"Help",
"ListMatch",
"SetScore",
"Top",
"Users",
"WhoBets"
]

with open(path + "/../Translations/lang.json", encoding="utf8") as json_data:
Expand Down
7 changes: 6 additions & 1 deletion Translations/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"You will be notified when a match is added.": "Vous serez notifié des nouveaux matchs ajoutés",
"Notify when a match is added.": "Etre notifié de l'ajout d'un match",
"The format of the date/hour is incorrect.": "le format de la date ou heure est incorrecte",
"An error ocurred adding the match.": "Une erreur est apparue lors de l'ajout du match."
"An error ocurred adding the match.": "Une erreur est apparue lors de l'ajout du match.",
"Fin de la prise des paris": "Fin de la prise des paris le : ",
"at": "à : ",
"Faites /whobets pour voir les positions des autres personnes": "Faites /whobets pour voir les positions des autres personnes",
"Faites /bet pour vous positionnez sur un match": "Faites /bet pour vous positionnez sur un matchs",
"Voici les paris enregistre pour ce match": "Voici les paris enregistré pour ce match."
}
}
2 changes: 1 addition & 1 deletion betBOT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datetime
from Settings.settings import *
from dotenv import load_dotenv
from sqlalchemy.orm import sessionmaker, relationship, lazyload, subqueryload, lazyload_all, subqueryload_all, joinedload

from telebot import TeleBot, types
from emoji import emojize
Expand Down Expand Up @@ -68,5 +69,4 @@
except:
print("Error enabling " + module)


bot.polling()

0 comments on commit 3fc838c

Please sign in to comment.