Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreyas-Sreelal committed Mar 19, 2023
1 parent c72f35e commit 8a07c89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ new TGBot:g_bot;
main() {
//Store bot token in SAMP_TG_BOT environment variable and connect from it
g_bot = TGConnectFromEnv("SAMP_TG_BOT");
g_bot = TG_ConnectFromEnv("SAMP_TG_BOT");
if(g_bot != INVALID_BOT_ID) {
printf("bot connected successfully!");
} else {
printf("Error: bot couldn't connect");
}
}
public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {
public OnTGMessage(TGBot:bot,TGUser:fromid[],TGMessage:messageid) {
if(g_bot != bot){
return 1;
Expand All @@ -69,51 +69,51 @@ public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {
chatname[56],
server_msg[128];
TGCacheGetMessage(message);
TGCacheGetUserName(username);
TGCacheGetChatName(chatname);
TG_CacheGetMessage(message);
TG_CacheGetUserName(username);
TG_CacheGetChatName(chatname);
format(server_msg,128,"[%s] %s(%d): %s",chatname,username,_:fromid,message);
format(server_msg,128,"[%s] %s(%s): %s",chatname,username,_:fromid,message);
SendClientMessageToAll(-1,server_msg);
return 1;
}
public OnTGUserJoined(TGBot:bot,TGUser:userid) {
public OnTGUserJoined(TGBot:bot,TGUser:userid[]) {
new
TGChatId:chatid[12],
username[24],
chatname[56],
server_msg[128];
TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
TG_CacheGetUserName(username);
TG_CacheGetChatId(chatid);
TG_CacheGetChatName(chatname);
format(server_msg,128,"User %s(%d) joined %s(%s)",username,_:userid,chatname,_:chatid);
SendClientMessageToAll(-1,server_msg);
return 1;
}
public OnTGUserLeft(TGBot:bot,TGUser:userid) {
public OnTGUserLeft(TGBot:bot,TGUser:userid[]) {
new
TGChatId:chatid[12],
username[24],
chatname[56],
server_msg[128];
TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
TG_CacheGetUserName(username);
TG_CacheGetChatID(chatid);
TG_CacheGetChatName(chatname);
format(server_msg,128,"User %s(%d) left %s(%s)",username,_:userid,chatname,_:chatid);
format(server_msg,128,"User %s(%s) left %s(%s)",username,_:userid,chatname,_:chatid);
SendClientMessageToAll(-1,server_msg);
return 1;
}
CMD:sendtgmessage(playerid,params[]) {
TGSendMessage(g_bot,CHAT_ID,params);
TG_SendMessage(g_bot,CHAT_ID,params);
return 1;
}
```
32 changes: 16 additions & 16 deletions pawn-examples/basic-bot/main.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
new TGBot:g_bot;

main() {
g_bot = TGConnectFromEnv("SAMP_TG_BOT");
g_bot = TG_ConnectFromEnv("SAMP_TG_BOT");
if(g_bot != INVALID_BOT_ID) {
printf("bot connected successfully!");
} else {
printf("Error: bot couldn't connect");
}
}

public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {
public OnTGMessage(TGBot:bot,TGUser:fromid[],TGMessage:messageid) {

if(g_bot != bot){
return 1;
Expand All @@ -27,30 +27,30 @@ public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {
chatname[56],
server_msg[128];

TGCacheGetMessage(message);
TGCacheGetUserName(username);
TGCacheGetChatName(chatname);
TG_CacheGetMessage(message);
TG_CacheGetUserName(username);
TG_CacheGetChatName(chatname);

format(server_msg,128,"[%s] %s(%d): %s",chatname,username,_:fromid,message);
format(server_msg,128,"[%s] %s(%s): %s",chatname,username,_:fromid,message);
print(server_msg);
SendClientMessageToAll(-1,server_msg);

return 1;
}


public OnTGUserJoined(TGBot:bot,TGUser:userid) {
public OnTGUserJoined(TGBot:bot,TGUser:userid[]) {
new
TGChatId:chatid[12],
username[24],
chatname[56],
server_msg[128];

TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
TG_CacheGetUserName(username);
TG_CacheGetChatId(chatid);
TG_CacheGetChatName(chatname);

format(server_msg,128,"User %s(%d) joined %s(%s)",username,_:userid,chatname,_:chatid);
format(server_msg,128,"User %s(%s) joined %s(%s)",username,_:userid,chatname,_:chatid);
print(server_msg);
SendClientMessageToAll(-1,server_msg);
return 1;
Expand All @@ -63,17 +63,17 @@ public OnTGUserLeft(TGBot:bot,TGUser:userid) {
chatname[56],
server_msg[128];

TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
TG_CacheGetUserName(username);
TG_CacheGetChatId(chatid);
TG_CacheGetChatName(chatname);

format(server_msg,128,"User %s(%d) left %s(%s)",username,_:userid,chatname,_:chatid);
format(server_msg,128,"User %s(%s) left %s(%s)",username,_:userid,chatname,_:chatid);
print(server_msg);
SendClientMessageToAll(-1,server_msg);
return 1;
}

CMD:sendtgmessage(playerid,params[]) {
TGSendMessage(g_bot,CHAT_ID,params);
TG_SendMessage(g_bot,CHAT_ID,params);
return 1;
}

0 comments on commit 8a07c89

Please sign in to comment.