Deleting command messages after sending them - c#

I started to write my own bot for a discord server using Discord.net. I already made the first command (which still doesn't work correctly, but that's for another story), and now that I am testing, it has a chat full of commands I sent. My goal is to instantly delete those messages as I send them (let's say I send .command something, and this should appear in a chat just for a little moment). I tried to look it up in documentation and some tutorials but couldn't find anything. I have only basic knowledge of programming, so I would be happy if you could tell me how to achieve this and explain how it works.

To answer the question of how to delete a message, you use the Context.Channel.DeleteMessageAsync function. It takes a message id as the parameter, so you will need to have the message data in memory at the time.
To answer the question of how to delete a message that you have just sent, you can use the above delete function alongside the Context.Message data which gives you the message data of the message that triggered the command. It will look like the following:
[Command("TestDelete")]
public async TestDeleteCommand()
{
await Context.Channel.DeleteMessageAsync(Context.Message.Id);
}
You can find more information of the DeleteMessageAsync function by looking at the Discord.Net docs

Related

How retrieve single message from queue EasyNetQ?

I am trying to implement the following solution: How to programmatically resend messages that have faulted with EasyNetQ? . One of the goals of this solution is to retrieve a single message from a given queue with the EasyNetQ library and without using subscriptions.
Regarding that, I am opening a new topic, because I cannot find any trace of the method GetMessageAsync in interface IAdvancedBus.
My code with unresolved method looks like that:
var message = await advancedBus.GetMessageAsync(errorQueue);
Do you know where I can find this method or if there is some other way to solve this?

Looking for Clarifications on SocketMessages and listening to channel in server bot belongs to

So I have a pretty extensive discord.net bot. The bot portion is really just going to be a place for the messages to be posted, but ultimately it queries multiple public APIs, deserializes the JSON response, then I do various tasks with the outcome data.
All of this is working just fine, and in fact, it posts to the correct channel, and I am able to swap in parameters for the data returned, etc. The intention of the bot is just to post information as it's updated from a composite of 4 sites that have public, queryable APIs. But this question is just for the wandering mind.
I basically mirrored this code for a simple test:
private static Task ClientOnMessageReceived(SocketMessage arg)
{
if (arg.Content.StartsWith("!helloworld"))
{
arg.Channel.SendMessageAsync("Message Response");
}
Now, the question is, if I send that same !helloworld in a channel, that the bot has access to, it does not respond to it. If I # my bot, it does not respond to it. It will only respond or even indicate that it's listening for DMs. Why? Does the SocketMessage object only work for DMs? If so, how would I listen to the text channels on a particular server and respond whenever any person says '!helloworld', the use for this is not one that I need for the bot. I just want to understand what I am missing. Ideally, I would want to see if someone says a funky phrase, so I can toss out a funkier response just for fun, however even in just my testing I can't figure it out.
So any help would be greatly appreciated, I thought I had a decent grasp on this library, but I am just not connecting the dots on this.
I logged into the discord developers here and then I added the privileged gateway intents > enabled this and the message content intent. I then add the following to my code before I initialized my discord socket:
public static DiscordSocketConfig config = new DiscordSocketConfig() {
GatewayIntents = GatewayIntents.All };
private readonly DiscordSocketClient _client = new DiscordSocketClient(config);
Since this bot is quite literally for myself and my friends, I do not need to worry about the 100 server threshold, unless folks start asking how I get all those cool deal histories and active deals posted in my server! Thanks!

Twimlets voice mail is cut off

I want to deliver voice message using Twilio. I also use text to voice twimlets as well. Here is the code
TwilioClient.Init(accountSid, authToken);
string responseurl = "http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CSay%3EDear%20John%20Smith%3C%2FSay%3E%0A%3CSay%3E%0AThis%20is%20a%20test%20for%20happy%20programing%20IVR.%20Why%20this%20is%20so%20hard%3F%3F%0A%3C%2FSay%3E%0A%3CPlay%3E%0Ahttp%3A%2F%2Fwww.pacdv.com%2Fsounds%2Fpeople_sound_effects%2Fapplause-4.mp3%0A%3C%2FPlay%3E%0A%3CSay%3EGood%20Bye%3C%2FSay%3E%0A%3C%2FResponse%3E&";
var call = CallResource.Create(to,from,url: new Uri(responseurl));
<Response>
<Say>Dear John Smith</Say>
<Say>
This is a test for happy programing IVR. Why this is so hard??
</Say>
<Play>
http://www.pacdv.com/sounds/people_sound_effects/applause-4.mp3
</Play>
<Say>Good Bye</Say>
</Response>
Here is the problem, When I pick up the call, I will hear all voicemail played. When it goes to the voicemail, It will cut the first 7 seconds recording off.
Anyone knows how to solve this problem?
Thanks
Twilio developer evangelist here.
The issue is that when your voicemail answers the phone it starts by reading its own message. At the same time, Twilio is reading the message out too, so when the voicemail starts recording the message is halfway through.
There are two ways you can get around this. Either you build a loop into your message to ensure that it all gets recorded. Or you can use Twilio's Answer Machine Detection to only start the message when it is sure that a human or machine has answered.
To use the AMD you need to pass another parameter when you create the call:
var call = CallResource.Create(
to, from,
url: new Uri(responseurl)
machineDetection: "DetectMessageEnd"
);
machineDetection can be either "Enable" or "DetectMessageEnd". "Enable" will call your webhook URL as soon as Twilio knows if it is human or machine, "DetectMessageEnd" will wait if it is a machine until the voicemail's message has ended, allowing you to play your message and have it fully recorded.
When Twilio requests your webhook URL, it will have an extra parameter too, AnsweredBy. You can use this to decide what course to take depending on whether a human or machine answered.
Let me know if this helps at all.

ActiveMQ access to previously published data on subscription

We're using ActiveMQ locally to transfer data between 5 processes that turn simultaneously.
I have some data I need to send to a process, both at runtime (which works perfectly fine), but also a default value on start. Thing is it is published when the process starts, it just doesn't read because it wasn't subscribed to the topic at the time the data was sent.
I have multiple solutions : I could delay the first publishing for a moment so that the process has time to launch (which doesn't seem very appealing) ; or is there a way to send all stored previously non-treated messages to some process that just subscribed ?
I'm coding in C#.
I don't have any experience with ActiveMQ, but other message system usually have an option which marks the subscription as persistent, which means that; after the first subscription; the message queue itself checks if a certain message is delivered to that system and retries with a timeout. In this scenario you need to start the receiver at least 1 time.
If this is not an option and you want to plug in receiver afterwards, you might want to consider a setup of your messages which allows you to retrieve the full state, i.e. if you send total-messages instead of differential- messages.
After a little google, I came upon this definition durable subscribers, I hope this helps:
See:
http://activemq.apache.org/how-do-durable-queues-and-topics-work.html
and
http://activemq.apache.org/manage-durable-subscribers.html
since you are using C# client i don't konw if this is supported
topic = new ActiveMQTopic("TEST.Topic?consumer.retroactive=true");
http://activemq.apache.org/retroactive-consumer.html
So, another solution is to configure this behavior on the broker side by adding that to the activemq.xml and restart :
The subscription recovery policy allows you to go back in time when
you subscribe to a topic.
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<subscriptionRecoveryPolicy>
<timedSubscriptionRecoveryPolicy recoverDuration="10000" />
<fixedCountSubscriptionRecoveryPolicy maximumSize="10000" />
</subscriptionRecoveryPolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
http://activemq.apache.org/subscription-recovery-policy.html
I went around the issue by sending a message from each process when they're launched back to the main one, and then only sending the info I needed to send.

Websphere MQ Message Read

At the moment I have a C# service that is reading messages off the queue (Websphere MQ) and writing them in a database.
Everytime I do a GET the message dissappears from queue. I would like an additional functionality though. I prefer to read a message off the queue and remove it in from the queue only after the write in the database was succesful. Please note I do all these in a multithreaded application. I know there is a way to browse the queue but this doesn't really provide the functionality I need.
I'm writing my firts WMQ application, and I know I'll run into this issue very soon, so I found your question.
I've found this http://www.mqseries.net/phpBB2/viewtopic.php?t=43043&sid=11ad2d587dbd19056836ccc3f8943e5f (specifing MQOO_BROWSE option while opening the queue) in other forum, I haven't tried it yet, but it think it worth a try...
[]'s
I have implemented similar functionality in C++. Hopefully this helps you or someone.
You can browse messages without removing them from the queue using options MQGMO_BROWSE_FIRST and MQGMO_BROWSE_NEXT.
How do I browse a Websphere MQ message without removing it?
Store message identifiers in a list or in any other suitable data structure.
Write messages to the database.
Then get messages from the queue normally without BROWSE option. ImqQueue::Get takes two parameters: options and ImqMessage. Set message identifier to ImqMessage-class before calling get. ImqMessage acts as a filter. You can select
only those messages that have been written successfully to the database.
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.amqzan.doc%2Fuc10330_.htm

Categories

Resources