I am trying to make this mineflayer bot attack specific players mentioned in chat - mineflayer

Is there a way to give the bot a command, and type someone's username in chat with the command, for example, "attack (username)", and have it attack that player?

const target = bot.players[username] ? bot.players[username].entity : null;
if(!target){
//action if requested player doesn't exist
}
bot.attack(target);

Related

I have a problem with InlineKeyboardButton in python telegram API

This is what my bot will do:
If someone sends a command like \sendFriendReq to my bot, then my bot will send a message with their details and an Inline Button with with "yes" and "no".
The problem I'm facing: How can i know who send those messages other than formatting the text with their details, is there a way to send their chat id along with the inline button so i can use that chat id to send a reply to my bot users
Disclaimer: This is not the actual problem but the solution to this problem could solve my problem so alternate solution to send friend req won't help me
This would give you pretty much every detail about the incomming message:
userid = update.message.from_user.id
firstname = update.message.from_user.first_name
lastname = update.message.from_user.last_name
fullname = update.message.from_user.full_name
username = update.message.from_user.name
message = update.message.text
chatid = update.message.chat_id

How to look up YouTube Live Chat Ban ID to delete it

The YouTube Live Streaming API has the ability to ban and un-ban a user from chat and provides the following method specifically to perform the un-banning:
https://developers.google.com/youtube/v3/live/docs/liveChatBans/delete
The API requires you to pass the id parameter that identifies the chat ban to remove and states that the value uniquely identifies both the ban and the chat. However, there does not appear any way to look up the chat bans for a channel, other than when you get the ID back initially when the ban occurs.
So is there no way to un-ban a user via the API long after the ban has occurred and you no longer have the ban ID?
Actually, LiveChatBanId is a base64-encoded string containing
banned user channel id
owner channel id
some random bytes?
Here is some python code that will generate it for you
import base64
banned_user_id = 'banned user id'
owner_channel_id = 'channel owner id'
decoded = f"\x08\x01\x12\x18{banned_user_id}\x1a8\n\r\n\x0b7cHT2DHCA7s*'\n\x18{owner_channel_id}\x12\x0b7cHT2DHCA7s".encode('utf-8')
encoded = base64.b64encode(decoded)
print(encoded)
Fill in banned_user_id and owner_channel_id
You may need to invoke the "LiveChatBans: delete" method twice, that's how Google works

How to obtain Telegram chat_id for a specific user?

How to obtain user chat_id in Telegram bot API?
The documentation says:
Integer | Unique identifier for the message recipient — User or GroupChat id
The message updates you receive via getUpdates or your webhook will contain the chat ID for the specific message. It will be contained under the message.chat.id key.
This seems like the only way you are able to retrieve the chat ID. So if you want to write something where the bot initiates the conversation you will probably have to store the chat ID in relation to the user in some sort of key->value store like MemCache or Redis.
I believe their documentation suggests something similar here, https://core.telegram.org/bots#deep-linking-example. You can use deep-linking to initiate a conversation without requiring the user to type a message first.
I created a bot to get User or GroupChat id,
just send the /my_id to telegram bot #get_id_bot.
It does not only work for user chat ID, but also for group chat ID.
To get group chat ID, first you have to add the bot to the group,
then send /my_id in the group.
Here's the link to the bot.
There is a bot that echoes your chat id upon starting a conversation.
Just search for #chatid_echo_bot and tap /start. It will echo your chat id.
Another option is #getidsbot which gives you much more information. This bot also gives information about a forwarded message (from user, to user, chad ids, etc) if you forward the message to the bot.
First, post a message in a chat where your bot is included (channel, group mentioning the bot, or one-to-one chat). Then, just run:
curl https://api.telegram.org/bot<TOKEN>/getUpdates | jq
Feel free to remove the | jq part if your dont have jq installed, it's only useful for pretty printing. You should get something like this:
You can see the chat ID in the returned json object, together with the chat name and associated message.
You can just share the contact with your bot and, via /getUpdates, you get the "contact" object
Using the Perl API you can get it this way: first you send a message to the bot from Telegram, then issue a getUpdates and the chat id must be there:
#!/usr/bin/perl
use Data::Dumper;
use WWW::Telegram::BotAPI;
my $TOKEN = 'blablabla';
my $api = WWW::Telegram::BotAPI->new (
token => $TOKEN
) or die "I can't connect";
my $out = $api->api_request ('getUpdates');
warn Dumper($out);
my $chat_id = $out->{result}->[0]->{message}->{chat}->{id};
print "chat_id=$chat_id\n";
The id should be in chat_id but it may depend of the result, so I also added a dump of the whole result.
You can install the Perl API from https://github.com/Robertof/perl-www-telegram-botapi. It depends on your system but I installed easily running this on my Linux server:
$ sudo cpan WWW::Telegram::BotAPI
Hope this helps
chat_id is nothing but id of user (telegram user account id). You can start a chat with #get_my_chat_id_bot. It will send you back the chat_id (your user_id).
There are following commonly used ids: channel id, group id, bot id, chat id(user id).
Straight out from the documentation:
Suppose the website example.com would like to send notifications to its users via a Telegram bot. Here's what they could do to enable notifications for a user with the ID 123.
Create a bot with a suitable username, e.g. #ExampleComBot
Set up a webhook for incoming messages
Generate a random string of a sufficient length, e.g. $memcache_key = "vCH1vGWJxfSeofSAs0K5PA"
Put the value 123 with the key $memcache_key into Memcache for 3600 seconds (one hour)
Show our user the button https://telegram.me/ExampleComBot?start=vCH1vGWJxfSeofSAs0K5PA
Configure the webhook processor to query Memcached with the parameter that is passed in incoming messages beginning with /start. If the key exists, record the chat_id passed to the webhook as telegram_chat_id for the user 123. Remove the key from Memcache.
Now when we want to send a notification to the user 123, check if they have the field telegram_chat_id. If yes, use the sendMessage method in the Bot API to send them a message in Telegram.
Whenever user communicate with bot it send information like below:
$response = {
"update_id":640046715,
"message":{
"message_id":1665,
"from":{"id":108177xxxx,"is_bot":false,"first_name":"Suresh","last_name":"Kamrushi","language_code":"en"},
"chat":{"id":108xxxxxx,"first_name":"Suresh","last_name":"Kamrushi","type":"private"},
"date":1604381276,
"text":"1"
}
}
So you can access chat it like:
$update["message"]["chat"]["id"]
Assuming you are using PHP.
Extending #Roberto Santalla answer and if you prefer to use Telegram API together with javascript and axios library then you might want the following:
const method = 'get'
const headers: any = {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
timestamp: +new Date(),
}
const options = { headers: { ...headers } }
const urlTelegramBase =
'https://api.telegram.org/bot123456:ABCDEF'
const urlGetUpdates = `${urlTelegramBase}/getUpdates`
const username = 'user_name'
const {
data: { result: messages },
} = await axios[method](urlGetUpdates, options)
const chat_id = messages.find(
messageBlock => messageBlock.message.chat.username === username
).message.chat.id
console.info('chat_id': chat_id)

Is it possible to send a single message to multiple numbers at a time using Twilio?

I'm developing an app that allows users to add people, info, and Name/phone, or select multiple numbers from their iPhone contact list to send SMS messages to the selected numbers. the problem is Twillio API needs to be call every time per number. Is their any way to call the API once for multiple numbers?
Is it possible to send message to multiple number at a time?
Is it possible to send multiple messages?
Thanks in advance
It's not possible, you need to iterate through the list and make one request per message (which is probably better than batching it and dealing with the potential of multiple errors / resends).
Each new SMS message from Twilio must be sent with a separate REST API request. To initiate messages to a list of recipients, you must make a request for each number to which you would like to send a message. The best way to do this is to build an array of the recipients and iterate through each phone number.
const numbersToMessage = ["+15558675310", "+14158141829", "+15017122661"]
numbersToMessage.forEach(async number => {
const message = await client.messages.create({
body: 'message body',
from: '+16468635472',
to: number
});
console.log(message.status)
});
Yes this is possible. Infact i'm trying to do the same thing at the moment(which is why i'm here) and Twilio has some advanced stuff that lets us achieve this.
Assuming you have a twilio ssid, twilio auth token and a twilio phone number, the next thing you have to do is create a "Twilio Messaging Service" from the dashboard. You can use the ssid of the created messaging service and use or if you want to send a message to like 10k numbers in one go, you create a "Twilio Notify Service" from the dashboard which takes the previously created messaging service as part of its configuration. Once this is done you can call the twilio.notifications.create() and pass bindings({ binding_type: 'sms', address: number }) for each phone number to it.
Complete explanation found in this twilio blog right here with perfectly working code.
https://www.twilio.com/blog/2017/12/send-bulk-sms-twilio-node-js.html
Yes it is possible to send message to multiple user's from your Twilio Number.
You can try this for your node.js file:
var arr = ["+1xxxxxxxxxx","+1xxxxxxxxx"];
arr.forEach(function(value){console.log(value);
client.messages.create({
to:value,
from: "+19253504188",
body: msg,
}, function(err,message){
console.log(err);
});
});
Yes it is possible. You have to provide the numbers as a list and iterate API call.
For example send a message to two numbers.
numbers = ['+1234562525','+1552645232']
for number in numbers:
proxy_client = TwilioHttpClient()
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
client = Client(account_sid, auth_token, http_client=proxy_client)
message = client.messages \
.create(
body="Your message",
from_='Your Twilio number',
to=number
)

Not able to get the type of MessageType in email app of symbian 3rd

I want to develpoe an app which sends email from IMAP4 settings of the phone.
And I am following this perticular wiki.
RSendAs send;
User::LeaveIfError(send.Connect());
CleanupClosePushL(send);
RSendAsMessage sendMsg;
sendMsg.CreateL(send,**KUidMsgTypeSMTP** );
CleanupClosePushL(sendMsg);
sendMsg.SetSubjectL(_L("Incident Capture."));
sendMsg.AddRecipientL(_L("abc#xyz.com"),RSendAsMessage::ESendAsRecipientTo);
sendMsg.SetBodyTextL(_L("Image Attached"));
TRequestStatus status;
//add attachment
sendMsg.AddAttachment(_L("C:\\Data\\Images\\hhj.jpg"),status);
User::WaitForRequest(status);
sendMsg.SendMessageAndCloseL();
CleanupStack::Pop();
CleanupStack::PopAndDestroy();
Now I want KUidMsgtypeSMTP Uid. I am not getting how to use this thing.
How do I get the value of this constant.
when I used random Hex value 0x040, it gave me System Error (-1) at run time.
Thanks in advance.
You need to #include <miutset.h> system header as it contains
const TUid KUidMsgTypeSMTP = {0x10001028}; // 268439592