C# .NET Core Discord Music Bot - c#

so I'm looking to code in some music functionality to a bot that I'm making. I've tried a whole bunch of different search terms but can't seem to come up with anything.
I'm writing the bot in C# .NET Core
I've got the basics down. Connects to a voice channel etc. But I'm not sure how to interface it with YouTube/Spotify so that it could search for url's or song titles.
So for example I'd like to be able to give it a link like this (either youtube or spotify):
Or be able to search Youtube (or both) for a song title:
I'm sure there's some kind of library to download or a NuGet package or API that I can integrate, but I just can't seem to find the right search terms to use to find any tutorials or documentation on the topic.
Any help in this area would be appreciated

Well I have been in your shoes and the best solution is to abandon all native ffmpeg and all and just use Sharplink. It uses lavalink to send audio to discord without actually connecting to it.
DiscordSocketClient client = new DiscordSocketClient();
LavalinkManager lavalinkManager = new LavalinkManager(client, new LavalinkManagerConfig
{
RESTHost = "localhost",
RESTPort = 2333,
WebSocketHost = "localhost",
WebSocketPort = 2333,
Authorization = "YOUR_SECRET_AUTHORIZATION_KEY",
TotalShards = 1
});
This is how you would get started.
Once a LavalinkManager is set up it will need to be started. It is recommended you put this in the ready event.
client.Ready += async () =>
{
await lavalinkManager.StartAsync();
}
Real the docs at https://github.com/Devoxin/SharpLink
Good Luck
**EDIT: **
I made my music bot public so https://github.com/rishav394/Dota-Geek/ here it is. Look out for the music section.

Related

Send RTSP Authentication C#

I am simply trying write a program in C# (windows forms) to play a video from an acquired URI that is password protected. The point of the program was to locate a URI using SOAPs and other means in order to stream a specific video feed. I didn't know the most difficult part of the project would be simply playing the video. I assumed there had to be libraries out there that could handle this. While there is plenty that can play a video, I am struggling to figure out how to handle RTSP streaming with authentication.
Tried formatting the URI object with UserName and Password. This throws a bad formatting error. Even though the final results follows good formatting according Wiki "IsWellFormedUriString" still throws an error.
local_uri.Host = deviceUri.Host;
local_uri.Port = 554;
local_uri.Scheme = "rtsp";
local_uri.Password = "admin";
local_uri.UserName = "admin";
//List full URI info.
infoBox.Text = local_uri.ToString();
//Past it to VideoView and start playing video.
bool check = Uri.IsWellFormedUriString(local_uri.Uri.ToString(), UriKind.RelativeOrAbsolute);
bool check = true;
if (check)
{
//_mp is of type LibVlcSharp.Shared.MediaPlayer
_mp.Play(new Media(_libVLC, local_uri.Uri));
check = false;
}
else
check = false;
I've tired to get a depreciated version of the VLC library working but seem to be running into the same issues. Looked through c# VLC lib and didn't find any function that would obviously handle authorization. I then started just trying to write code to handle, buffer, and play the data. I think this will be out of the question for how time consuming it is and given the time constrains on this assignment.
I know the URI i get back is valid. I can open VLC and entire the URI. A moment later the following pops up...
Once its entered I see a RTSP package sent to the URL...
DESCRIBE rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1 RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="IP Camera(C6990)", nonce="61218496a6adcf4869f748505626d63a", uri="rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", response="3cce04175b5b1a3d0a6a8dcfea9d377a"
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
Then of course the URL responds with an 200 Ok and starts streaming. It would be great if I could figure out how to recreate this event in C#. I had a recommendations of doing a Dialog API but cannot figure out how to work that out with the VLC Object. Any direction would be greatly appreciated. Hindsight I should not have chosen a different project as this is attached to my grade.
As it turns out (and I'm not entirely sure why) but the code above does work as long as your password does not contain anything that would cause string formatting error. For example, the password cannot contain an "#" symbol with the code above. I'm sure there is a workaround for this but have not figured out what it is.

Integrating Azure Search with Virtual Assistant Template bot

I currently have a fully functioning Virtual Assistant Template-based chatbot with a skill attached to it. My goal is for the skill to work as a search function that can find resources in a CosmosDB and pull them back for the user to use. After doing some research I believe the best way to do this would be to use Azure search to retrieve said info. From what I've seen in the Virtual Assistant Template documentation integration with Azure Search should definitely be possible... I just haven't found any examples or tutorials on how to do so. If anyone knows how to create an azure search resource and integrate it into a bot, or knows of a resource that tells you how to do so, please let me know!
For your scenario, an outline of what to do is:
Create an Azure search service
In that create an indexer that will point to your Cosmos DB data source. Here is documentation specific to how you can crawl through your data in Cosmos DB: https://learn.microsoft.com/en-us/azure/search/search-howto-index-cosmosdb
Once your indexer runs and has crawled through your data, it should be available for searching, from the app in your search index.
There isn't an end to end tutorial about integrating with a bot, but here is an Azure search tutorial that shows an complete scenario of crawling through a SQL database and then searching using full-text search.
https://learn.microsoft.com/en-us/azure/search/search-indexer-tutorial
You should be able to follow most of the guidance there, except replace the parts about SQL indexer with details from Cosmos DB indexer in the link above.
I want to do a similar search (only in AzureBlob instead of Cosmos DB). I am using sdk v4 for my bot framework and Visual Studio 2019. I'm trying to call the service through the code below:
public ISearchIndexClient CreateSearchIndexClient()
{
string searchServiceName = "MySearchServiceName";
string queryApiKey = "MySearchServiceKey";
string indexName = "MyIndexName";
SearchIndexClient indexClient = new SearchIndexClient(searchServiceName, indexName, new SearchCredentials(queryApiKey));
return indexClient;
}
public async Task StartAsync(ITurnContext turnContext, string searchText){
ISearchIndexClient infoClient = CreateSearchIndexClient();
string indexname = infoClient.IndexName;
DocumentSearchResult<Document> results = infoClient.Documents.Search(searchText);
await turnContext.SendActivityAsync(MessageFactory.Text($"Here should be the results: {results} \n...and then my index: {indexname}."));
}
It runs without errors, so one could use it. But it never shows the message at StartAsync. If anyone sees what I am missing, thank u in advance.

How do i use the Steam SDK to login?

I wanted to do a program where I can add a few accounts, to login with one click.
I tried to add a dll as reference but that didn't work.
The problem is, I dont know how I use the sdk (folder) that i downloaded, in my C# WinForm project.
Thanks for help
Well the docs at SteamKit2 are pretty straight forward. I coded a bot for myself and dont know if it works on the latest version of steam client but yeah i have a clear idea about what to do.
If you have a look here you create a new steamClient and subscribe to events.
_steamClient = new SteamClient();
and then connect to the client.
_manager = new CallbackManager(_steamClient);
_steamUser = _steamClient.GetHandler<SteamUser>();
_steamFriends = _steamClient.GetHandler<SteamFriends>();
_manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
_manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
_manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
_manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff);
_manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo);
_manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
_manager.Subscribe<SteamFriends.FriendMsgCallback>(OnChatMessage);
_manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendList);
Console.WriteLine("Connecting to steam in 3s");
_steamClient.Connect();

Google Cloud PubSub V1 using GCloud Emulator

I'm fighting with Google Docs for setting up Cloud PubSub with .NET using a PubSub emulator.
https://cloud.google.com/dotnet/docs/getting-started/using-pub-sub
https://cloud.google.com/pubsub/docs/publisher
https://cloud.google.com/pubsub/docs/emulator
Coming from a Rails background, I'm tasked to implement Cloud PubSub for a .NET product, running our google cloud on .NET Core, to enable it to publish.
Google::Cloud::Pubsub.new(project: project_id, emulator_host: emulator_host)
From the documentation using .NET, I keep coming back to the following:
PublisherServiceApiClient publisherClient = PublisherServiceApiClient.Create();
PublisherClient publisher = PublisherClient.Create(...)
However, the library used from the docs Google.Cloud.PubSub.V1 -Pre
does not contain the definition.
'PublisherClient' does not contain a definition for 'Create'.
Instead, I get CreateAsync that takes in TopicName, PublisherClient.ClientCreationSettings and PublisherClient.Settings.
https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.PubSub.V1/api/Google.Cloud.PubSub.V1.PublisherClient.html
I noticed that PublisherServiceApiClient can take in a Channel, but I'm confused on how to get this going.
To conclude with an actual question, how does one currently implement Cloud PubSub with .NET for in cloud and then locally with emulator? Adding to that, am I using the wrong library or the wrong docs?
Any suggestions, pointers or piece of advice would be truly appreciated.
I managed a solution that I am happy with.
Instead of using the PublisherClient, I went with using the PublisherServiceApiClient alone.
emulatorAddr = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");
if (emulatorAddr != null)
{
channel = new Channel(emulatorAddr, ChannelCredentials.Insecure);
pub = PublisherServiceApiClient.Create(channel);
}
else
{
pub = PublisherServiceApiClient.Create();
}
Which meant that publishing was slightly more involved then sending string to the PublisherClient, but overall not so bad.
PubsubMessage msg = new PubsubMessage
{
Data = ByteString.CopyFromUtf8(JsonConvert.SerializeObject(payload))
};
pub.PublishAsync(topic, new[]{ msg });
If the project is running in a Google Compute Engine, it will have default credentials. Otherwise, wether you're running an emulator locally or in docker you can define PUBSUB_EMULATOR_HOST.
What really helped was this https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.PubSub.V1/index.html
To make the PublisherClient connect to a local emulator, you need to pass custom ServiceEndpoint and ChannelCredentials to CreateAsync:
var serviceEndpoint = new ServiceEndpoint(theEmulatorHost, theEmulatorPort);
var publisherClient = await PublisherClient.CreateAsync(
topicName,
new PublisherClient.ClientCreationSettings(credentials: ChannelCredentials.Insecure, serviceEndpoint: serviceEndpoint));
To switch to the real PubSub, just leave away the ClientCreationSettings.
You can use the EmulatorDetection property on the ClientCreationSettings using extension method .WithEmulatorDetection(EmulatorDetection.EmulatorOrProduction). Like this:
PublisherClient publisher = await PublisherClient.CreateAsync(
topicName,
new PublisherClient.ClientCreationSettings()
.WithEmulatorDetection(EmulatorDetection.EmulatorOrProduction));
This will work if you have the following environment variable for the local emulator endpoint: PUBSUB_EMULATOR_HOST=localhost:8085
(If you use Visual Studio you might have to restart VS for the environment variable to be detected)
In windows I had problems using the set PUBSUB_EMULATOR_HOST=localhost:8085 command, so I ended up adding it manually.
Details here: https://cloud.google.com/pubsub/docs/emulator
Extra tip: you can add topics directly to API using curl: curl -X PUT http://localhost:8085/v1/projects/my-project-name/topics/my-topic

c# windows mobile Text messaging

I have mad an application for windows mobile which can do different mobile functions with the numbers the application has.
Anyway. I want to start the Text message application and send a phonenumber as an argument.
I have only found this:
SmsMessage sms = new SmsMessage();
sms.Body = "This is a message";
sms.To.Add(new Recipient(sNumber));
sms.Send();
But i want to use the text messaging application in the mobile device.
Any tip?
thanks in advance
As a start, have you looked to see if this discussion is relevant to what you want to do? One thing it mentions is using CE MAPI and COM interop. There's also the Mobile In The Hand library.
There are other links in that discussion too.
Take a look at the MessagingApplication class, in particular its DisplayComposeForm static method. You should be able to use a code snippet such as the following to get the built in messaging application to appear.
SmsMessage sms = new SmsMessage();
sms.Body = "This is a message";
sms.To.Add(new Recipient(sNumber));
MessagingApplication.DisplayComposeForm(sms);
I also have a blog post available with a sample application that in part demonstrates using this API - http://www.christec.co.nz/blog/archives/495.

Categories