Skip to content

Commit

Permalink
Merge pull request Desenvolvimento-de-Software#22 from mleandrojr/master
Browse files Browse the repository at this point in the history
Fixed user/chat saving and rules parser.
  • Loading branch information
mleandrojr authored Aug 1, 2024
2 parents 5931114 + 314df1c commit da2ee81
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class App {

const response = await request.post();
if (response.ok) {
Log.info("Commands successfully registered.");
Log.info("Commands successfully registered");
}
}
}
3 changes: 3 additions & 0 deletions src/action/Greetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default class Greetings extends Action {
}

text = text.replace("{userid}", this.context.newChatMember!.getId());
text = text.replace(/\n/g, "<br>");
text = text.replace(
"{username}",
this.context.newChatMember?.getFirstName() || this.context.newChatMember?.getUsername()
Expand Down Expand Up @@ -144,6 +145,8 @@ export default class Greetings extends Action {
return options;
}

Lang.set(this.chat.language || "us");

const captchaButton: InlineKeyboardButton = {
text: Lang.get("captchaButton"),
callbackData: JSON.stringify({
Expand Down
5 changes: 5 additions & 0 deletions src/action/SaveUserAndChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export default class SaveUserAndChat extends Action {
return Promise.resolve();
}

if (!chatId) {
Log.save("SaveUserAndChat :: Chat ID not found " + JSON.stringify(this.context.getPayload()));
return Promise.resolve();
}

UserHelper.updateUser(contextUser);
ChatHelper.updateChat(this.context.chat);

Expand Down
3 changes: 2 additions & 1 deletion src/command/Rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Rules extends Command {
}

const chat = await ChatHelper.getByTelegramId(this.context.chat.getId());
Lang.set(chat.language || "us");
Lang.set(chat?.language || "us");

this.command = command;
this.chat = chat;
Expand Down Expand Up @@ -125,6 +125,7 @@ export default class Rules extends Command {
return this.context.chat.sendMessage(Lang.get("rulesNotFound"));
}

const text = result[0].rules.replace(/\n/g, "<br>");
return this.context.chat.sendMessage(result[0].rules, { parseMode: "HTML" });
}

Expand Down
3 changes: 2 additions & 1 deletion src/helper/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export default class ChatHelper {
.where("id").equal(row.id);

try {
currentChat.execute();

await currentChat.execute();

} catch (err) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/helper/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class UserHelper {
.set("last_name", user.getLastName() || null)
.set("username", user.getUsername() || null)
.set("language_code", user.getLanguageCode() || "us")
.set("is_channel", user.getId() > 0 ? 1 : 0)
.set("is_channel", user.getId() > 0 ? 0 : 1)
.set("is_bot", user.getIsBot() || 0)
.set("is_premium", user.getIsPremium() || 0);

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ console.log(" / \\ __| | __ _ | | _____ _____| | __ _ ___ ___");
console.log(" / _ \\ / _` |/ _` | | | / _ \\ \\ / / _ \\ |/ _` |/ __/ _ \\");
console.log(" / ___ \\ (_| | (_| | | |__| (_) \\ V / __/ | (_| | (__ __/");
console.log("/_/ \\_\\__,_|\\__,_| |_____\\___/ \\_/ \\___|_|\\__,_|\\___\\___|");
console.log("");
console.log(" ");

new App();

0 comments on commit da2ee81

Please sign in to comment.