Python Telegram Minesweeper Bot https://github.com/isjerryxiao/tgmsbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from peewee import *
SQLITE_MAX_INT: int = 2**63 -1
SQLITE_MIN_INT: int = -2**63
SQLITE_MAX_INT = SQLITE_MAX_INT // 2
SQLITE_MIN_INT = SQLITE_MIN_INT // 2
db = SqliteDatabase('tgmsbot.db', pragmas={
'journal_mode': 'wal',
'cache_size': -32 * 1000})
class SafeIntegerField(IntegerField):
field_type = 'INT'
def adapt(self, value):
try:
ivalue = int(value)
if ivalue > SQLITE_MAX_INT:
rvalue = SQLITE_MAX_INT
elif ivalue < SQLITE_MIN_INT:
rvalue = SQLITE_MIN_INT
else:
rvalue = value
return rvalue
except ValueError:
return value
class Player(Model):
user_id = SafeIntegerField(unique=True, primary_key=True)
mines = SafeIntegerField()
death = SafeIntegerField()
wins = SafeIntegerField()
restricted_until = SafeIntegerField()
immunity_cards = SafeIntegerField()
permission = SafeIntegerField()
class Meta:
database = db
db.connect()
db.create_tables([Player])
def get_player(user_id):
player = Player.get_or_none(Player.user_id == user_id)
if player is None:
player = Player.create(user_id=user_id, mines=0, death=0, wins=0,
restricted_until=0, immunity_cards=0, permission=0)
return player
else:
return player