Discord.py days since account creation autorole - discord

Is there any way to check a users account creation date when they join a server and give them a role if their account is over 14 days old in discord.py?

Yes!
To check when a user joined use:
member.joined_at
This returns a datetime object, which allows you to use a timedelta to determine when the user should get the role:
joinedDate = member.joined_at
tdelta = datetime.timedelta(days=14)
dateToAddRole = joinedDate + tdelta
You can then run a check with the new datetime object to see if the current date is the date the member should get the role
if datetime.now() == dateToAddRole:
await member.add_roles(guild.get_role(roleid))

Related

How to match a specific string inside a string fetched from database in MVC 5?

So I am building a project where I need to fetch date from the database and on the basis of the given month,
as I need to find customers who have birthday on the given month. I have a query that works perfectly fine in the SQL server but I don't get its equivalent in Linq.
So here is my query that runs in SQL
SELECT * FROM CustReg
WHERE DOB LIKE '_____month%'
I need to match that month as it should come in the 6th position of that DOB string.
Demo Database-
Id Name DOB
1 AB 1995-02-20
2 CD 1998-04-13
4 EF 1991-02-15
5 GH 1988-06-8
6 IJ 2000-02-09
Query - Select all Employee whose birthday comes on feb.
Expected Output - AB,EF,IJ.
PS- I have taken datatype of DOB string not Date or DateTime.
I also have month in string (for eg '02' for feb)that I have fetched from the input date.
If I have understood your question right, may be the following code helps.
First create a enum of Months,
public enum Month
{
Jan=1,Feb,Mar,Apr,May,Jun,July,Aug,Sep,Oct,Nov,Dec
}
Now use the following query to get what u wanted,
Month requiredMonth = Month.Feb;
var res = CustReg.Where(x => (Month)Enum.Parse(typeof(Month), x.DOB.Substring(5, 2)) == requiredMonth).Select(x => x.Name);
foreach (var item in res)
{
Console.WriteLine(item);
}

sending reminder mail when specific no. of days are left Which is manger by the Query SQL Server?

i want to send the Email on Certification expiry when 21,14,7,3,2,1 days are left by a scheduler which picks the data by the Query .
i am using the ExpiryNotification bit col.as a flag(as previous it used to sent on 30 days only)
the data in the Query is picked from scheduler.now if i have to do changes in the Query to implement this logic i will need to change the col from bit to int and check the Notification col.but what if the Scheduler does not run when 21 days are left for some odd reason then what will happen.is there any other way to implement this Logic by sql server ?
it will make the ExpiryNotification col value to 1 when the mail is send
exisitng Query (checking only 30 days)
Select * from wsm_certification
where
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 30
and wsm_Certification.ExpiryNotification = 0)
You may try something like this
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 21 OR (DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 14
Use in operator to check multi values
Eg:
Select * from wsm_certification
where
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) in (21,14,7,3,2,1)
and wsm_Certification.ExpiryNotification = 0)

Retrieving Oracle Password_Verify_Function

I am an IS auditor and I would like to check how we can retrieve the PASSWORD_VERIFY_FUNCTION assigned to users. I understand the script utlpwdmg.sql can be executed to setup the default password resource limits.
If changes were made using ALTER PROFILE, the script utlpwdmg.sql will not show the latest settings.
Please let me know what SQL commands I can execute to show what is the PASSWORD_VERIFY_FUNCTION stored and used in the system.
You can use this query to see source code of stored proc:
--Source of all password functions.
select *
from dba_source
where owner = 'SYS'
and name in
(
--The name of all password functions in use.
--See DBA_USERS.PROFILE to determine which user is using which profile.
select limit
from dba_profiles
where resource_name = 'PASSWORD_VERIFY_FUNCTION'
--Yes, this is intentionally the string 'NULL', that's what Oracle uses here.
and limit <> 'NULL'
)
order by name, line;
To find out what users are using PASSWORD_VERIFY_FUNCTION, you need to find out which profiles are using the function and then see which users are assigned that profile.
select profile from dba_profiles where limit = 'PASSWORD_VERIFY_FUNCTION';
select username from dba_users where profile = ;

Can't select User ID from Salesforce

I'm trying to select user's subordinates from Salesforce, but a simple query
SELECT Id FROM User WHERE ManagerId=xxxxxxxxx
returns bunch of null values, when I run
SELECT Id,Name FROM User WHERE ManagerId=xxxxxxxx
I get the correct names, still no IDs.
Is this a permission issue? I can't find anything when I login to portal.
I'm running the queries via API on Sandbox environment.
Try this (both works for me allways):
Id myId = [Select Id From User Where Username = 'myUserName'].Id;
System.debug('#### myId: ' + myId);
List<User> myIdList = [Select Id From User Where Username = 'myUserName' Limit 1];
System.debug('#### myId from list: ' + myIdList[0].Id);
Portal Licence doesn't allow to query User. However you have still access to the name of the user through OwnerId, CreatedById, LastModifiedById using in an inputfield.
i.e :
If you want to have access to user through the portal you need a custom object and synchronise your records with User by trigger.

Facebook Credits API PHP - Update user_id in mySql database after purchase

I have an app where I want users to be able to buy in-game credits called coins.
I have set my callback url, and can make a purchase, I get an order_id and settled from the callback, but how do I update the users row in my mySql database after they have made the purchace.
Kinda how my mySql DB looks
ID......FBID............Name..........Coins
7.......1000***797....John..............0
After the user has bought 200 coins for 1 credit, I would like to do this
$SQL = "UPDATE tb_users SET Coins = Coins+200 WHERE FBID = '$usernumber'";
$result = mysql_query($SQL);
But how and where am I supposed to do that? Is it in the callback.php file or in the index.php file after "var callback = function(data)".
I can't seem to pass the user_id from the form on the index to callback.php
So how do I do that, and if that is possible, am I supposed to update my database in the callback.php file??
Nevermind found this out. You can get the info about the user via API the normal way and update the DB in callback.php after "settled".

Resources