discord.py How to use loops - discord.py

async def kick(ctx):
role = ctx.guild.get_role(1066518590813118494)
for member in ctx.guild.members:
if role in member.roles:
await member.kick(reason='Test')
I want to loop this phrase
I want to be banished after holding a certain role for a certain period of time.
I've been studying iterative statements, but it's difficult to understand.
Please understand that I am using a translator due to my lack of English.

You should look up tasks. You can have a task looping every X INTERVAL and then during that interval, check if a user needs removing from a particular role. If your bot is the one assigning the role in the first place; then you could store the time that role was assigned in a data structure somewhere (like a dict, list, whatever), in a file locally, or in a database. You can then use that in the task to do the check to see if a user needs their role removing.

Related

Webi: On opening, filter data by current user name which can be in or not in a given list (no prompt)

(SAP BusinessObjects BI Platform 4.3 Support Pack 1 Patch 11 Version : 14.3.1.4142.11)
Disclosure: I'm not born english speaking, but if I have understood correctly, we should now use "they", instead of he/she, etc. That is what I did here. Just to be sure no one is confused while reading.
Hi everyone, it's me again for a webi question.
I have this report in which I have data for a group of workers. These data are: their name, when they work, where, which activity they do, etc.
Worker name
Other information
Worker A
...
Worker B
...
...
...
Worker M
...
Worker Z for example is not in the list.
I currently have a filter "name" (multi-list), which allows us to select one or more workers (Worker A, Worker B,...). By default, it shows all data.
There is an auto-refresh on opening.
The function CurrentUser() returns the worker ID, not the name.
Worker name
Worker ID
Worker A
238x01f93
Worker B
4j192h60a
...
...
Worker Z
09ad812jn
I have two kind of user, that can see this report:
A user whose name is present in the list of workers (e.g. Worker A).
A user whose name is not present in the list of workers (e.g. Worker Z).
My goal:
When the user opens the report, the filter "name" is set by default with their name (e.g. Worker A). This way, they see only their data. If they want to see the data of other workers, they can easily change the filter to select other workers (e.g. Worker B and C). It should not be limited.
When the user (Worker Z) opens the report, they see all data. They can naturally use the filter to select only one or a few workers if they want to.
What I did/tried:
I can change things in the view (database), in the universe or/and in the report. I only tried things on the report level, because I could not see any ways to help me solve this on universe or view level. (But I am open to suggestions! :-) )
Create a variable to:
Filter for only current user ID. It worked, but only if the user name was in the list. Another problem is that the workers don't know this user ID and can't work with it.
=CurrentUser()
Search in the list, if the current user ID exists. Does not work. It shows always all data.
If (Pos([Personalnumber];CurrentUser()) > 0) Then CurrentUser() Else [Personalnumber]
Link the current worker ID with their name if they are in the list. It worked well for them, but I could not find a way to have all workers, if the current user name is not in the list.
If (CurrentUser() = [Personalnumber]) Then [Name] Else "All"
I read so many posts, but none for my case. It is often to prevent user to see all the data, which is not what I want. They should be able to see everything, if they want to.
We only want to filter for the current user for performance means and also efficiency. The user does not have to select themselves the right filter and loose time. Most of the time, they only wants to see their data.
Can anyone help me?
Don't hesitate to tell me if something is unclear or missing. :-)
Thanks for your time!

Power Automate Get Planner Task Assignee Names

I'm working on a Power Automate flow where the flow is supposed to connect to Planner, get the tasks which are due tomorrow and send a message to an MS Teams Channel.
I got the entire flow working except of one thing - getting the names of the person(s) whom the task is assigned.
Here's my current flow:
Getting the list of Tasks from Planner,
Filter those which have a Due Date set,
Filter the ones which have the Due Date tomorrow,
Get the Name of the Task Creator using Get User Profile,
Send the data into an MS Teams Channel.
This all works perfectly fine. However I also need to get the names of the Assigned users. I understand that they come as an array. And when I try to add it to the same Get User Profile it's getting wrapped into an unnecessary "Apply to Each" which breaks everything.
Does anyone have a clue how this can be solved? Basically I need only 1 Assignee as we are not going to assign the same task to more than 1 person.
Any help would be much appreciated!
In order to avoid the loop (which is also a valid approach, long story) then you can use an expression to get the first (in case there are multiple) assigned user.
This is an example where you don't need to loop ...
... you can see I've initialised a (string) variable at the top which will hold the user ID GUID.
... then further down in the Set Assigned To operation, this is the expression I use ...
item()?['_assignments'][0]['userid']
That gets the first user and then the associated userid property. You can then pass that into the Get user profile (V2) task ...
Obviously, you need to adapt that to your flow but I hope that makes sense.

Role of off-chain workers

I'm trying to build a mental model of the role of off-chain workers in substrate. The bigger picture seems to be that they move logic inside the substrate node, that was otherwise done by oracles, triggering on predefined transactions. There are two use cases I was thinking of specifically:
1: Validating file formats: incoming transaction proposes a file accessible via url or ipfs hash, and it's format needs to be validated. An off-chain worker fetches the file, asserts format (size, encoding, content, whatever) and if correct submits another transaction saying it's valid.
2: Key generation: let's assume there is a separate service distributed with the substrate node, which manages keys for each instance. Node A runs a key sharing algorithm (like Shamir's secret sharing) via this external service between participants A, B and C, then makes a transaction creating a group (A,B,C) on-chain. This transaction triggers all nodes that are in this group to run off-chain workers, call into their local key store verifying having the key. They can all mark it on-chain afterwards.
As far as I understand it correctly, off-chain workers are triggered in every node after block execution. In the former use case, this would result in lots of transactions validating just one file, and nothing guarantees the correctness of these. What is a good way of reaching consensus on the validity of the file? Is it also possible without economic incentives like staking? It would be problematic with tokens having no value in the network, e.g in enterprise settings. Is this even the right use case for off-chain workers? The second example should not suffer from such issue, we just need all parties to verify having the key.
Where does the thought process above go wrong, and why?
As far as I understand it correctly, off-chain workers are triggered in every node after block execution.
Yes and no. There is a CLI flag for it. And at the time of this writing it says:
--offchain-worker <ENABLED>
Should execute offchain workers on every block.
By default it's only enabled for nodes that are authoring new blocks. [default: WhenValidating] [possible
values: Always, Never, WhenValidating]
In the former use case, this would result in lots of transactions validating just one file, and nothing guarantees the correctness of these.
I think it is the responsibility of the receiving function (aka. Call) to handle and incentivise this. For example, there could be a reward opportunity to validate an address. But, if it has already been submitted by another transaction, you will get slashed (or even if not, you do pay some transaction fee, for nothing). In such cases, you can assume that not all participants will submit a transaction. They will only do it when there is a chance of improvement, which should be depicted by your potential reward/slash scheme.
Is this even the right use case for off-chain workers?
I am no expert here, but I think at least the validation example is a good example. It is just a matter of finding a good incentive + anti-spam slashing.
I am less familiar with the second example, so no comments on that.

Can I add assigns to the “main socket” after the connection is already established?

As explained by this post, when the client first connects with the server, a “main socket/process” gets created and holds its assigns. Later, when the client joins specific channels/topics, each channel’s socket/process copies those assigns and can add to them as it will.
I now have a use case where, upon the user joining their own individual channel (i.e. user:#{user_id}), I retrieve some information about the user from the DB, which should then be globally available to all channels this user later joins. However I haven’t been able to find a way to put those information into socket.assigns so that they can be available everywhere. If I try to assign them, they will only be available in the socket.assigns of this particular user:#{user_id} channel.
Is there a way to do it? Should I just instead simply try to fetch all those information in one go when the user first connects, instead of when they join the individual user channel?
Different channels mean different sockets.
The easiest solution would be to maintain the permanent state (Agent, ETS, DETS, mnesia, ...), holding a map user_id => user_info and query this state whenever you need this info.

In Parse, how can you remove someone from a role after requesting the resource X times?

In my Parse app, I want Users to have access to an audio file only ten times.
Once they have listened to it 10 times, I don't want them to be able to access it.
Essentially, from my current understanding about Parse, I would have to somehow remove them from a role while keeping some kind of secure counter somewhere.
Is there a clean simple way to do this?
Based on your comment about around 100 items, I think the easiest way to handle this is with something akin to a join table.
Essentially, you will have a new Parse database class, call it 'Uses', that tracks how many uses of an item each user have. It will have the following fields:
user (Pointer): The user in question
resource (Pointer): The resource (audio file they have accessed)
count (Number): The number of times they have used the resource
Your logic in the app should be as follows:
Query the Uses table for items where user = current user and resource = requested resource
If doesn't exist, create one and set the count = 1
If does exist, check the count
Count < 10? Play the item
Count > 10? Throw an alert
If security is paramount, you could do this via a Cloud Code call instead to prevent an unscrupulous (but very very smart) user from altering their entries in the Uses table. It depends on how paranoid you need to be.
Hope that helps!

Resources