Arti0mka / Projekt1pository

This my new repository. :) Ha-ha ha
0 stars 0 forks source link

Make buttons 3 * 3 #19

Open Arti0mka opened 3 years ago

Arti0mka commented 3 years ago

Can you check the code?

import os
import sys
import subprocess
import telebot
import time
from telebot import types
import ast
#pip3 install pytelegrambotapi --upgrade

oButtonConfig = {"one": "key_one", "two": "key_two", "three": "key_three"}
oButtonConfig = {"four": "key_four", "five": "key_five", "six": "key_six"}
oButtonConfig = {"seven": "key_seven", "eight": "key_eight", "nine": "key_nine"}
def makeKeyboard(oArr):
        markup = types.InlineKeyboardMarkup()
        a1 = types.InlineKeyboardButton(text="1",callback_data="key_1")
        a2 = types.InlineKeyboardButton(text="2",callback_data="key_2")
        a3 = types.InlineKeyboardButton(text="3",callback_data="key_3")
        a4 = types.InlineKeyboardButton(text="4",callback_data="key_4")
        a5 = types.InlineKeyboardButton(text="5",callback_data="key_5")    
        a6 = types.InlineKeyboardButton(text="6",callback_data="key_6") 
        a7 = types.InlineKeyboardButton(text="7",callback_data="key_7")    
        a8 = types.InlineKeyboardButton(text="8",callback_data="key_8")    
        a9 = types.InlineKeyboardButton(text="9",callback_data="key_9")    
        markup.add(a1,a2,a3)
        markup.add(a4,a5,a6)
        markup.add(a7,a8,a9)
        return markup
        for value,key in oArr.items():
         markup.add(types.InlineKeyboardButton(text=value,      
                 callback_data="['value', '" + value + "', '" + key + "']"))
        return markup

bot = telebot.TeleBot('1287725214:AAEPpUk4MmCQOl5FDBs5IiF3zzNRQXHnB6Q')

@bot.callback_query_handler(func=lambda call: True)
def handle_query(call):
    if (call.data.startswith("['value'")):
        valueFromCallBack = ast.literal_eval(call.data)[1]
        messTXT = ast.literal_eval(call.data)[2]
    if messTXT == "key_one":
        bot.send_message(chat_id=call.message.chat.id,text="you send one button")
    elif messTXT == "key_two":
        bot.send_message(chat_id=call.message.chat.id,text="you send two button")
    elif messTXT == "key_three":
        bot.send_message(chat_id=call.message.chat.id,text="you send three button")
    elif messTXT == "key_four":
        bot.send_message(chat_id=call.message.chat.id,text="you send four button")
    elif messTXT == "key_five":
        bot.send_message(chat_id=call.message.chat.id,text="you send five button")
    elif messTXT == "key_six":
        bot.send_message(chat_id=call.message.chat.id,text="you send six button")
    elif messTXT == "key_seven":
        bot.send_message(chat_id=call.message.chat.id,text="you send seven button")
    elif messTXT == "key_eight":
        bot.send_message(chat_id=call.message.chat.id,text="you send eight button")
    elif messTXT == "key_nine":
        bot.send_message(chat_id=call.message.chat.id,text="you send nine button")
    else:
        bot.send_message(chat_id=call.message.chat.id,text="write artem for create new keyboard")

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    print(message.text)
    if message.text == "/help":
        bot.send_message(message.from_user.id, "i am stupit")
    elif message.text == "artem":
        bot.send_message(chat_id=message.chat.id,
                text="Here are the general tasks",
                reply_markup=makeKeyboard(oButtonConfig),
                parse_mode='HTML')  
    else:
        bot.send_message(message.from_user.id, "i undestend write /help.")

bot.polling(none_stop=True, interval=0) 
ihsinme commented 3 years ago

re-turn indicates a return from a function.

therefore this part will never be executed. it is superfluous.

        for value,key in oArr.items():
         markup.add(types.InlineKeyboardButton(text=value,      
                 callback_data="['value', '" + value + "', '" + key + "']"))
        return markup
Arti0mka commented 3 years ago

And why when I click on them then they do not work?

ihsinme commented 3 years ago

https://github.com/Arti0mka/Projekt1pository/pull/20

Arti0mka commented 3 years ago

And now how to do to play tic-tac-toe?

ihsinme commented 3 years ago

since you skipped boring topics like

1.compare one version of the program with another

  1. understand how the piece works
  2. on a piece of paper, paint what has changed in the programs

then your question is logical.

but I remind you that you should already understand that there is no focus. everything works as you write.

you have one program that plays tic-tac-toe in the console, there is a program that plays in the telegram. It seems to me that you need to do that the third would play in the telegram on the buttons.

and let's start asking questions about what exactly is not clear, and we will not return to the fact that I will not let you think again, and I will write a new program for you.

learn.

Arti0mka commented 3 years ago

Can you please tell me where to start to write tic-tac-toe with buttons in the telegram?

Arti0mka commented 3 years ago

And then I can’t help but understand how I’m already trying to insert something and what’s not working out?

Arti0mka commented 3 years ago

I have already checked the programs.

Arti0mka commented 3 years ago

Can you help how to move further with the creation of tic-tac-toe. What to do next?

ihsinme commented 3 years ago

we agreed to create a list of what has not been done. I have not seen him until now.

Arti0mka commented 3 years ago

I'll finish the lessons now and send them.

Arti0mka commented 3 years ago

1 ) How to combine buttons with tic-tac-toe? 2 ) How to set the sequence of moves? 3 ) How to make a beautiful field? 4 ) How to play with an opponent?

Arti0mka commented 3 years ago

I closed it by accident.

Arti0mka commented 3 years ago

Hello El Padoro Differences In tele.py, there are no functions for building a board, determining the winner, placing numbers in ascending order, determining the winner and loser and a draw. There is no winning code.

Arti0mka commented 3 years ago
                                                 Work

There is only one function in tele.py. When I write any text, tele.py says "i undestend write \ help." When I write \ help, tele.py says "i am stypit."

Arti0mka commented 3 years ago
                                           Work

There are many functions in tele1.py. The first function of building a board. The second function is to enter a number from 1 to 9, if I enter a number greater than 9, then tele1.py will write "Invalid input. Please enter a number from 1 to 9 to be like." The second part of the second function is responsible for placing crosses and zeroes. If I look where there is already a cross or a zero, then tele1.py will write "This cell is already taken." The second function also contains victory codes. In the last function, as well as in tele.py, it is responsible for the text. When I write / help tele1.py writes "hello my dear hoziain im a you slav" and if I write text that is not involved in the program tele1.py writes "i undestend write / help." Even when I write "gogo" then the program is activated and you can play tic-tac-toe. And it is written whether the player won or lost.

ihsinme commented 3 years ago

OK. it really looks good already.

let's compare "Add file.py" and tele1.py

Arti0mka commented 3 years ago
                                                Differ

Add file.py is a python tic-tac-toe game and tele1.py This is a tic-tac-toe game written in Python and played through telegrams. They differ in that in tele1.py in telegram, and Add file.py in Python. Tele1.py has commands for example: 'text', / help, "gogo", "tt".

ihsinme commented 3 years ago

I need you to describe the difference in great detail. for example, I printed these two files and wrote what each line in both files does what is the same and what has changed.

every line.

it is very important that you see the difference, this is learning.

if you find pieces that are not clear at all, then mark them as complex and in the second iteration we will analyze them.

Arti0mka commented 3 years ago
                                                      Work

Add file.py has four functions. The first function is responsible for building the field. And spreading numbers. The second function is responsible for placing crosses and zeroes. The third function is responsible for the winning code. The fourth function is responsible for writing a message whether the player won or lost or draw.

Arti0mka commented 3 years ago

There are many functions in tele1.py. The first function of building a board. The second function is to enter a number from 1 to 9, if I enter a number greater than 9, then tele1.py will write "Invalid input. Please enter a number from 1 to 9 to be like." The second part of the second function is responsible for placing crosses and zeroes. If I look where there is already a cross or a zero, then tele1.py will write "This cell is already taken." The second function also contains victory codes. In the last function, as well as in tele.py, it is responsible for the text. When I write / help tele1.py writes "hello my dear hoziain im a you slav" and if I write text that is not involved in the program tele1.py writes "i undestend write / help." Even when I write "gogo" then the program is activated and you can play tic-tac-toe. And it is written whether the player won or lost.

ihsinme commented 3 years ago

thanks we are starting to move after the break. let's call and discuss in the evening.

the only thing to be more careful, I wrote that you need to unpack and be ready to discuss every line.

Arti0mka commented 3 years ago
bot = telebot.TeleBot('1287725214:AAEPpUk4MmCQOl5FDBs5IiF3zzNRQXHnB6Q')
arin = 0
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    global arin
    arin = arin + 1
    print(message.text)
    if message.text == "/help":
        bot.send_message(message.from_user.id, "i am stupit")        
    if message.text == "Рокси":
        arin = 0
    print(message.text)
    if arin == 21:
     bot.send_message(message.from_user.id, "очко") 
    else:
        bot.send_message(message.from_user.id, arin)

bot.polling(none_stop=True, interval=0)
ihsinme commented 3 years ago

good. why you do not create file in repository?

Arti0mka commented 3 years ago

ElPadro why when I want to display the user.id in the error it says name 'user' is not defined.

ihsinme commented 3 years ago

try

  1. message.from_user.id
  2. str(message.from_user.id)
Arti0mka commented 3 years ago

ElPadro can tell you how to do the task that you gave. It just got better today and started to work.

ihsinme commented 3 years ago

try

  1. message.from_user.id
  2. str(message.from_user.id)

You try this?

Arti0mka commented 3 years ago

Yes

Arti0mka commented 3 years ago

ElPadro, please tell me how to do the second task.