I am making a discord bot and currently trying to make the bot repeat what the user says.
cService.CreateCommand("say")
.Parameter("user", ParameterType.Unparsed)
.Do(async (e) =>
{
Message[] CopiedMessage = await e.Channel.DownloadMessages(1);
await e.Channel.SendMessage(CopiedMessage); //Error, only can print string
});
I am right now having problems trying to print out the CopiedMessage as it's datatype is Message[] and I have to convert to a string to make the bot say it. I tried converting it to a string using ToString but it still doesn't work.
Try defining your CopiedMessage using string CopiedMessage = e.Args[0]; instead.
DownloadMessages() is mainly used for deleting messages on the channel, although it can be used to print out after some complex process. Even if it works , since it is not a string, it will give out a weird string of numbers anyway since you downloaded the message's data, not the message's value.
Related
I have an Excel Add-In on the Ribbon using C# which grabs data from an API, but the password used for the API may change from time-to-time.
Without going into the myriad of security issues that may exist by gathering the PW for this purpose directly within the add-in, I'm not able to even determine how to display an Input Box, much less get user input entered into it and then pass it back to the program.
I have researched the _Application.InputBox Method but can't seem to get that to work. I always get a response such as The name 'InputBox' does not exist in the type '_Application'.
The code at this point is very simple, just:
using Excel = Microsoft.Office.Interop.Excel;
try
{
myToken = RequestToken("name#domain.com", "MyPass");
}
catch
{
Excel._Application.InputBox inputPassword = new Excel.Application.InputBox(); // this is where i get the error
myToken = RequestToken("name#domain.com", inputPassword.value);
}
Again, the purpose here is to try the "default" password. If it fails, ask the user for the updated password (the username won't change) and then we will re-try. Ideally, we'd like to mask the password input, but we can cross that bridge later.
The key here is to not have to re-deploy the entire app with a hard-coded password every time it changes on the server-side.
In a perfect world, I would probably store the updated password somewhere else (.ini file, registry, etc) instead of asking every single time when the "default" password failed. But again, this is a very early first step.
Please keep in mind this is a custom add-in to be used only by a single user, and we are still in testing, so I will probably move to a more robust security method down the road, but for now, this is the best option I have.
Any help will be greatly appreciated.
I'm following the Cloud Code Guide from Parse and got to the point of successfully uploading a script with a sample function called "hello" to the cloud. The function returns string "hello world" when you call it.
Now I have to run it, and this is where I stumble: there is no example available on how to do that from Unity C# environment. There are examples for curl, iOS applications, JS and so on, but not for that environment.
The closest one is a "Windows" example, I guess, which reads like this:
var result = await ParseCloud.CallFunctionAsync<IDictionary<string, object>>("hello", new Dictionary<string, object>());
Except Unity only has .NET 3.5 features, so there is no async. And except this example is not covering how to extract the actual response like examples for other platforms do.
Parse asset package for Unity adds it's own solution for the async problem called Tasks, so I guess I should just use that, just like in Unity Guide examples on standard functions like queries. I guess I can call my "hello" function and read it's "hello world" response using this code:
var helloTask = ParseCloud.CallFunctionAsync<IDictionary<string, object>> ("hello", new Dictionary<string, object> ()).ContinueWith (t =>
{
IDictionary<string, object> result = t.Result;
if (result != null)
{
string response = (string) result["result"];
if (!string.IsNullOrEmpty (response))
Debug.Log (response);
}
});
It did not work, of course, or I would not be asking that question. No errors, but no log either. I modified the code above to warn me in the log if string above is indeed null or empty, or if result object is null, but I'm not getting any messages even in that case, which leads me to assume I'm using ParseCloud.CallFunctionAsync completely incorrectly, with anything past ContinueWith not even being called.
What would be the correct way of calling a custom Cloud Code function from Unity then?
I am using twilio api for voice message.
my code look like:
public bool SendVoiceCall(string FromNumber, string ToNumber)
{
string URL = "http://twimlets.com/message?Message%5B0%5D=" + "hi, abc thanks for registration your code is : 7,2,4,9";
URL = URL.Replace(" ", "%20");
string AccountSid = "##########";
string AuthToken = "##########";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var options = new CallOptions();
options.To = ToNumber;
options.Url = URL;
options.From = FromNumber;
options.Method = "GET";
var call = twilio.InitiateOutboundCall(options);
}
I am having problem when call goes customer cannot listen message properly due to speed of the call message. So we need to have call in which customers can listen code properly with slow speaking words. Please advice me how can i make it slowly speaking code for my customers?
Regards,
Jatin
When saying numbers, '12345' will be spoken as "twelve thousand three
hundred forty-five." Whereas '1 2 3 4 5' will be spoken as "one two
three four five."
Punctuation such as commas and periods will be interpreted as natural
pauses by the speech engine.
is useful for saying dynamic text that would be difficult to
pre-record. In cases where the contents of are static, you might
consider recording a live person saying the phrase and using the
verb instead.
If you want to insert a long pause, try using the verb.
should be placed outside tags, not nested inside them.
http://www.twilio.com/docs/api/twiml/say
So I'd recommend using either more commas or try using the pause tag if possible
Slow down Twilio's TwiML "Say" command for text-to-speech numbers
Slow down Twilio's TwiML “Say” command for standard text on text-to-speech
I am working with the C# Event Log API in Windows (essentially everything in System.Diagnostics.Eventing.Reader).
I have an EventMetadata object and pull its Description property to retrieve the message template for an event.
Generally, these templates look similar to the following:
Network interface reports message %1
These variables are easily replaceable with actual data whenever I receive an event.
(EventLogRecord.Properties match up to the placeholders)
Here is where my problem comes in. The EventLogRecord.Properties sometimes contain different kinds of placeholders. These always begin in %% and I cannot find a way of resolving them.
As an example:
// This method is triggered when a new event comes in
async public static void ListenerEvent(object s, EventRecordWrittenEventArgs args) {
var evt = (EventLogRecord)args.EventRecord;
// This method retrieves the template from a ProviderMetadata object
// And replaces all %n with {n}
// So that we can string.Format on it
var tmp = TemplateCache.TemplateFor(evt);
// Need this since the indices start with 1, not 0
var props = new List<object> {string.Empty};
props.AddRange(evt.Properties.Select(prop => prop.Value));
// Now the message should be human-readable
var msg = string.Format(tmp, props);
}
Using the above example template, the Properties might be ["%%16411"] and now I end up with the following message
Network interface reports message %%16411
I figure my question now is, how do I replace this %%16411?
I have looked into ProviderMetadata and the rest of its properties but none seem to match up.
Any help figuring out how to resolve these placeholders (or even what they are/where they come from) is appreciated.
An event that shows this behaviour is 5152, as found here: http://community.spiceworks.com/windows_event/show/452-microsoft-windows-security-auditing-5152
Thank you.
I'm having problems trying to send an XMPP message to a 'Room' in our OpenFire instance. The end result is for our CruiseControl.NET build server to be able to send success/failure messages to the appropriate 'Rooms' as an additional means of notification.
I'm using the Matrix XMPP library to create a Console Application in C# using VS2010. The idea was to create a simple .exe that I can wire up to CCNet and pass a few arguments into as required.
The code below is basically the sample code from the Matrix site/documentation which I have updated to point to a room.
static void Main(string[] args)
{
var xmppClient = new XmppClient
{
XmppDomain = "SERVER",
Username = "davidc",
Password = "*********"
};
xmppClient.OnRosterEnd += delegate
{
xmppClient.Send(new Message
{
To = "roomname#conference.SERVER",
From = "davidc#SERVER",
Type = MessageType.groupchat,
Body = "Just Testing the XMPP SDK"
});
};
xmppClient.Open();
Console.WriteLine("Press return key to exit the application");
Console.ReadLine();
xmppClient.Close();
}
I can send to an individual user (changing the To and Type accordingly) without any problems but changing the code to point to a room ends in silence! Is there some additional 'handshaking' that needs to be done to address a room?
I don't really have to use C# for the solution as long as it will run on a Windows Server.
You'll want to read XEP-0045, "Multi-User Chat". You need to enter the room before sending a message to it. For a quick fix, see section 7.1.1, which shows how to join a room using a simplified (older) protocol:
<presence
to='darkcave#chat.shakespeare.lit/thirdwitch'/>
For the newer protocol, include an extra x tag from section 7.1.2:
<presence
to='darkcave#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
I don't know your library, but you'll want code something like:
xmppClient.Send(new Presence
{
To = "roomname#conference.SERVER/mynick",
});