Discord bot : Check who invited someone - c#

I'm creating a discord bot which rewards users for the amount of invites they have.
The API allows you to retrieve the invitecount of an user when they do !invites for example however this can be easily botted so I'm trying to find a way to prevent botters.
Current code :
[Command("test")]
public async Task InviteCheck()
{
var test = await Context.Guild.GetInvitesAsync();
foreach (var tests in test)
{
if (Context.User.Username + "#" + Context.User.Discriminator == tests.Inviter.ToString())
{
//amount of invites
await Context.Channel.SendMessageAsync(tests.Uses.ToString());
}
}
}
So I got this idea to check when an user joins and then check their invite link, but apparently this is not included in the API.
In the documentation : https://discord.foxbot.me/docs/api/Discord.IInviteMetadata.html
it shows that I can retrieve the inviter information (I'm not certain) but I have no clue on how to use Iinvitemetadata.
Tldr; I want to make a discord bot which checks howmany valid invitations an user has, delete the invitation if the invited user leaves. User must be in group for 10 minutes before counting as an invitation.

You can check for an event when a new user joins the guild. See here
But i think Stackoverflow is not the right place for that kind of question since it is very vague and you won't get full out of the box solutions from users.
In your place i would grab the source code from their github repository and make my way through what it can do and how.
Alternativly you should ask this kind of question in the official unofficial "Discord API" Discord-Server where there is an extra channel for your library Discord.Net called "#dotnet_discord-net" - Here you go.

Related

How to get the teams user details without accessing the bot

Is there any method or new features available in teams to get new user details without accessing the particular bot?
There is a possibility of implementing roaster to grab the user details like user ID and object ID based on the azure active directory. We can get the information based on the number of entries per page minimum to 50 count users. The type of information we can get is like when the user log in into the system and what are the operations done by the user based on the name ID.
Python:
async def _show_members(
self, turn_context: TurnContext
):
members = await TeamsInfo.get_team_members(turn_context)
}
Credit: surbhigupta

Check if user ID exists in Discord server in c#

I'm trying to make a auth link that the user will open then to get the client id from the user and check if the user is exists in a server. I'm not sure what lib should I use would love to get help thank you. I saw this code but this is in JavaScript and I need it in c# + the part of auth link
USER_ID = '123123123';
if (guild.member(USER_ID)) {
// there is a GuildMember with that ID
}```
DSharpPlus is a fairly simple library to use. It'll throw 404 not found when the user isn't found so you'll need to check the ClientErrored event for failure.
var guild = //get current guild somehow
var user = await guild.GetMemberAsync(USERID);
Documentation on GetMemberAsync: https://dsharpplus.emzi0767.com/api/DSharpPlus.Entities.DiscordGuild.html#DSharpPlus_Entities_DiscordGuild_GetMemberAsync_System_UInt64_
Repo: https://github.com/DSharpPlus/DSharpPlus
D#+ vs Discord.Net is DNet will give you more control over handling of events and messages. D#+ is more plug and play kind of deal.

Can't get Unity Firebase userID

I'm trying to save the user data to the firebase realtime database directly after the user has been created. But the problem is not the saving, but the UserID. I save also save the user ID that i get from CurrentUser. and then i check in the realtime database and saw that the ID that stored was from a last user who recently created. And i check it in the editor by getting the current user Email and it showed the last user Email not the current user who are creating at the moment. Can someone help me to get the current user ID and not the last user id.
You guys can see the image from the links.
What ID should be
The last user ID showing up instead You guys can see that the ID don't event match. I did try redo the project and looking at the videos that from firebase it self. I really have no ide what to do, i am stuck for 3 days now.
public void SaveNewUserInCode(string userId, string Name, string Email) {
var currentUser = FirebaseAuth.DefaultInstance.CurrentUser;
string userNameId;
if (currentUser != null)
{
userNameId = currentUser.Email;
user = new User(userId, Name, Email);
string Json = JsonUtility.ToJson(user);
reference.Child("Users").Child(currentUser.UserId).SetRawJsonValueAsync(Json);
Data.text = userNameId;
}
}
It would be helpful to see the code that invokes SaveNewUserInCode.
I see a few potential dangers with the code you've posted:
The first is that any call (other than Auth.SignOut) is asynchronous. If you're caching userId immediately after Auth.SignInWithEmailAndPasswordAsync, you'll likely have the previous user still in Auth.CurrentUser (until the related task completes). See my related post on all the ways to wait for a task in Unity if you think this is the issue.
The second, especially if Email is sometimes null, you may be automatically calling Auth.SignInAnonymouslyAsync every time your app starts (perhaps old logic, I usually start my prototypes with anonymous users and later on add real accounts when it's time to do some user testing). This will always overwrite your current user even if you were previously signed in anonymously. You should always check Auth.CurrentUser before calling any of the Auth.SignIn methods, but definitely make sure that you don't have a stray Auth.SignInAnonymouslyAsync laying around.
If the issue is threading, I believe the following logic will fix your problem:
var auth = FirebaseAuth.DefaultInstance;
auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWithOnMainThread(task => {
// omitted : any error handling. Check task's state
var user = task.Result;
SaveNewUserInCode(user.UserId, user.DisplayName /* or however you get Name */, user.Email);
});

Contact presence/status on Lync 2013 SDK shows "Presence unknown" until manual client search

I'm working on an automation service for lync that will automatically add people to an IM conversation based on their availability/lync "presence". It essentially goes down a list, checks who is online, and adds the first person to a call.
The problem I'm getting is that sometimes (usually when lync had to be restarted), it does not always fetch the contact's presence.
First I just had it grab the presence. Then I added code to check for the ContactInformationChanged event firing, but that does not seem to happen unless I go into the app and manually type the alias I'm looking for.
Is there a Refresh() method I'm missing somewhere? Or is there any way to force it to find this? Here's my search methods:
public Contact GetContact(string emailAddress)
{
Contact user;
lock (ContactLookupCache)
{
while (!ContactLookupCache.TryGetValue(emailAddress.ToLower(), out user))
{
lock (Client)
{
Client.ContactManager.BeginSearch(emailAddress, this.HandleContactLookup, null);
}
Monitor.Wait(ContactLookupCache);
}
}
return user;
}
public string GetContactPresenceState(Contact contact)
{
string presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
// see if the status is either "Presence unknown" or "Updating..."
if (IsUnknownPresenceState(presenceStatus))
{
lock (contact)
{
//bug?? This event seems to only fire sometimes when you search on the app for contact details
contact.ContactInformationChanged += (object sender, ContactInformationChangedEventArgs e) =>
{
if (e.ChangedContactInformation.Contains(ContactInformationType.Activity))
{
lock (contact)
{
presenceStatus = contact.GetContactInformation(ContactInformationType.Activity).ToString();
if(!IsUnknownPresenceState(presenceStatus))
Monitor.PulseAll(contact);
}
}
};
Monitor.Wait(contact);
}
}
return presenceStatus;
}
Also, sorry for the crappy code... I was just trying to get it to work and kept throwing more junk code in hoping something would help.
Could you verify that the code works fine for all the contacts in your contact list and it's just the ones that aren't listed where presence change events aren't raised correctly?
This makes sense to me given you are using the client SDK which will only tell you about events the client is interested in. For example it would be pretty traffic intensive if all 85,000 clients received the presence changes for the other 85,000 clients in a company.
I think you are in the realms of either polling the presence at regular intervals or adding the contacts to the client (perhaps under a relevant group just to keep things tidy).
Failing that you may want to looking into the UCMA SDK which is better suited to centralised services than the client SDK.

How do I get Google Calendar feed from user's access token?

Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}

Categories