Discord.py send dynamic time string - python-3.x

I'm currently working on a Bot where users can ask to play a game and set when to play it:
.play Valorant #30 -> "#anyone_who_is_playing_valorant, up for a round in 30 minutes?"
Currently, I'm editing the message every minute to display the correct time left, which unfortunately makes implementing other commands and functions way more difficult as it should be (while loop etc).
My only solution would be to display the time at which 30 minutes would be passed:
Message written at 17:00 -> "#anyone_who_is_playing_valorant, up for a round at 17:30?"
but due to timezones the displayed timestring has to be different for each user.
Actually, Discord supports such a function for embeds, but I haven't found a standart support for sending dynamic timestrings. I would imagine it to be like Pings, where there is no function but a syntax for it: <#!authorid>
Is there a way to send dynamic timestrings?

There is no dynamic time syntax in Discord messaging, the only such functionality is the timestamp in embeds as you mentioned.

Actually there is a way to have a dynamic string in your message but it does not work for the footer in the embed.
You only need to make a unix code,
from datetime import datetime
import calendar
date = datetime.utcnow()
utc_time = calendar.timegm(date.utctimetuple())
print(utc_time)
your output looks something like this: 1657723929
You format the code to this: <t:unixcode:R>
and it gives you
7 minutes ago
You can also make a timestamp which leads to the future with just adding the secconds to the unix code you just made e.g.:
this code <t:2665824929:R> represents
in 32 years
depends on when you see this because its dynamic

Related

How i can turn datetime to like "one minute age" in prisma node js graphql?

I'm trying to set the date time in Prisma migrate to human like one minute age, one month ago how I can manage to do it?
You can use the Internationalization API Intl to do just that.
It would look something like:
const formatter = new Intl.RelativeTimeFormat('en') // specify language here
console.log(formatter.format(-5, 'minutes')) // 5 minutes ago
console.log(formatter.format(5, 'months')) // in 5 months
Note that you need to specify the amount of time in English but if you change the language of the formatter, it will adapt the output to the specified language.
Of course you first need to calculate the amount of time first, but that shouldn't be difficult :)

Dialogflow console returning different result to when sent through the API (Where the wrong timezone is used)

I have a DialogFlow agent set up where one intent is used to schedule reminders. I can say something like:
"At 5pm remind me to go for a run"
And it returns the sentence to remind (in this case 'go for a run') as well as the time to set the reminder using #sys.date-time.
This works as intended, I am able to get the correct time because it just sends the time without a timezone attached.
When I use a command such as:
"In 15 minutes remind me to go for a run"
it sends the result as the time using the timezone, in this case, the incorrect one.
So right now, a result for the date-time using the API was:
2020-11-09T14:20:33+01:00
which is an hour more than it should be.
I have checked the DialogFlow agent's default time zone where it is set to:
(GMT0:00) Africa/Casablanca
Which I am fairly certain is the correct one for London time. However moving to a different timezone changes it and actually gives the correct one for the timezone (Just not my timezone)
Leaving me to wonder if this time zone is broken?
Regardless though, the Dialogflow console on the webpage returns the correct date-time but in a different format using 'startDateTime' and 'endDateTime', something that the agent does not do when sent using the API.
I have checked all configurations within the program and cannot find any evidence of any code giving a new timezone and in fact have tried to add the London timezone when a query is sent but this does not resolve the issue.
Does anyone have any advice on how to solve this?
EDIT:
After receiving a good suggestion from a user I am reminded of the most puzzling part of this issue. Chaning the timezone to GMT -1:00 vs 0:00 actually having a difference of two hours.
Around 1pm I queried it to get the time in 15 minutes.
When it was set to GMT-1:00 Atlantiv/Cape_Verde the time returned is:
2020-11-10T12:21:15-01:00
When it was set to GMT0:00 Africa/Casablanca the time returned is:
2020-11-10T14:22:07+01:00
Neither is the correct time and despite the timezone suggesting a 1 hour difference, it is actually 2 hours apart.
For London the correct timezone should be GMT -1, Casablanca Africa is GMT+1, I used this web page to determine this.
If you are in London is recommended to configure your agent to sue the correct time zone (GMT-1).

The following code has been giving me the same output for a long time

I have been writing some code with PRAW. I want the following to give the top posts each day.But it has been returning the same ids even though new posts are submitted each day and different posts are at the top. What should I do?
import praw
reddit=praw.Reddit(client_id='id',
client_secret='secret',password='password',
user_agent='agent',username='username')
top_funny=subreddit.top(limit=1)
for submission in top_funny:
print(submission)
by default subreddit.top() returns the top of all time. You can change this by using the time_filter parameter and specify any of the following: hour, day, week, month, year, all.
ex:
subreddit.top("day", limit=1)
will return the top submission from today.
As LampToast said, you should use the time_filter.
Arguments for .top() are listed in the docs:
Parameters: time_filter – Can be one of: all, day, hour, month, week, year (default: all).
https://praw.readthedocs.io/en/latest/code_overview/models/multireddit.html#praw.models.Multireddit.top

How can I to restrict the execution of an imacros script between some hours?

I have an imaros script that runs each 4 minutes (using auto clicker)... but I need to it doesn't run between 23:30 to 00:30... so I need to do something like:
If (date is <23:30 and date is > 00:30) then run!!
Is this possible?
many thanks!
This is possible with JavaScript. You can create current time in JS and compare it with time between the two times you named. It's a little complicated to make. Msg me on private messages and we can work things out.

Reading emails with groovy (Java Mail)

I am using groovy in order to access gmail and read the Inbox. It is regular JavaMail and will not describe it here.
So for simplicity, after I connect to the store, I use this:
folder.open(Folder.READ_ONLY)
folder.messages.each { msg ->
...
doSomething with msg
...
}
this is working fine.
However I have a performance issue. Sometimes messages[] could be big. Some folders contain more than 1000 messages, and checking them all takes time.
I am looking for a quicker way to get only those emails that are the most recent (for example messages from the last 5 days or something like that)
of course I have the date information in each msg and I could do my comparison, but this is not efficient since it will loop through the entire collection.
Is there a better way to get those messages?
If you have JavaMail issue a SEARCH command with the criterion SINCE 04-JAN-2011, you'll get back the set messages in the currently-selected folder delivered since January 4th. (SENTSINCE 04-JAN-2011 will do the same thing, only based on the "Date" message header.)
Something along the lines of this:
folder.search(new ReceivedDateTerm(ComparisonTerm.GE, sinceDate));

Resources