Ehm uchun dastur (Ma’lumotlar bazasi) nomi



Download 66 Kb.
bet3/3
Sana16.11.2022
Hajmi66 Kb.
#867089
1   2   3
Bog'liq
8802823fbc330e0febe94b947c5c2bdfee06

Enter a word";
break;
case "ru":
text += "Введите слово";
break;
case "tr":
text += "Bir kelime girin";
break;
}

sendMessage.setText(text);


sendMessage.setParseMode("HTML");
executeMsg(sendMessage,message.getChatId());

}

private void translator(Message message) {



SendMessage sendMessage;

if(userState.containsKey(message.getChatId())) {


if (userState.get(message.getChatId()).equals("langFrom")) {
sendMessage = new SendMessage();
sendMessage.setText("Translator\nChoose From language");
sendMessage.setParseMode("HTML");

sendMessage.setReplyMarkup(db.getInlineKeyboard(Arrays.asList(new String[]{


"\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67\uDB40\uDC7F English",
"\uD83C\uDDF9\uD83C\uDDF7 türk",
"\uD83C\uDDF7\uD83C\uDDFA Русский"}),
Arrays.asList(new String[]{"en", "tr", "ru"})));
executeMsg(sendMessage, message.getChatId());
}
}
}

private void start(Message message) {

SendMessage sendMessage = new SendMessage();
sendMessage.setText("Assalamu Alaykum Translator botga hush kelibsiz");
sendMessage.setParseMode("HTML");
sendMessage.setReplyMarkup(db.getReplyKeyboard(Arrays.asList(new String[]{"\uD83D\uDD01 Choose language", "\uD83D\uDCC3 About program"})));
executeMsg(sendMessage,message.getChatId());

}

private void executeMsg(SendMessage sendMessage, Long chatId) {



sendMessage.setChatId(chatId.toString());
try {
execute(sendMessage);
} catch (TelegramApiException e) {
throw new RuntimeException(e);
}

}

@Override


public String getBotUsername() {
return "";
}

@Override


public String getBotToken() {
return "";
}
}
package service;

import model.Word;


import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardButton;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;

import java.time.LocalDate;


import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Database {

private static Database db = new Database();

public static Database getDB(){


return db;
}

public String from;


public String to;

public InlineKeyboardMarkup chooseLangMarkup = getInlineKeyboard(Arrays.asList(new String[]{


"\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67\uDB40\uDC7F English",
"\uD83C\uDDF9\uD83C\uDDF7 türk",
"\uD83C\uDDF7\uD83C\uDDFA Русский"}),
Arrays.asList(new String[]{"en", "tr", "ru"}));

public InlineKeyboardMarkup getInlineKeyboard(List names, List callback) {


InlineKeyboardButton button;

List row = new ArrayList<>();


List> keyboard = new ArrayList<>();

int k = 0;


for (String name : names) {

button = new InlineKeyboardButton();


button.setText(name);
button.setCallbackData(callback.get(k++));
row.add(button);
if(k%2==0) {
keyboard.add(row);
row = new ArrayList<>();
}
if(k==callback.size()){
keyboard.add(row);
}
}

InlineKeyboardMarkup markup = new InlineKeyboardMarkup();

markup.setKeyboard(keyboard);

return markup;


}

public ReplyKeyboardMarkup getReplyKeyboard(List names) {

KeyboardButton button ;
KeyboardRow row = new KeyboardRow();
List keyboard = new ArrayList<>();
int k=0;
for (String name : names) {

button = new KeyboardButton();


button.setText(name);
k++;
row.add(button);
if(k%2==0) {
keyboard.add(row);
row = new KeyboardRow();
}

if(k==names.size()){


keyboard.add(row);
}

}

ReplyKeyboardMarkup markup = new ReplyKeyboardMarkup();


markup.setSelective(true);
markup.setOneTimeKeyboard(false);
markup.setResizeKeyboard(true);
markup.setKeyboard(keyboard);
return markup;
}

public Word createWord(String line) {

Word word = new Word();
String s = ""; int fir = 0,last = 0;
System.out.println("working");

if(line.contains("def\":[{\"text\":\"")){


fir = line.indexOf("def\":[{\"text\":\"");
last = line.indexOf("\",\"pos\":\"");
System.out.println(fir+ " " + last);
s=line.substring(fir+15,last);
word.setText(s);
System.out.println(line);
line = line.substring(last+3);
System.out.println("cut: " + line);
}

if(line.contains("pos\":\"")){


fir = line.indexOf("pos\":\"");
last = line.indexOf("\",\"ts\"");
System.out.println(fir+ " " + last);
s=line.substring(fir+6,last);
word.setPos(s);
line = line.substring(last+3);
}

if(line.contains("tr\":[{\"text\":\"")){


fir = line.indexOf("text\":\"");
last = line.indexOf("\",\"pos");
System.out.println(fir+ " " + last);
s=line.substring(fir+7,last);
word.setTr(s);
line = line.substring(last+5);
}

LocalDateTime localDateTime = LocalDateTime.now();

word.setTime(localDateTime.toString());
return word;

}
}



Download 66 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish