Bot not detecting server members (Discord.py) - command

I have a command that I made to choose a random member for the server, but for some reason, whenever I run it, it only mentions itself.. As if it cannot detect that there are other members in the server besides itself. Here is the code:
ok
client = commands.Bot(command_prefix=['%', "v", "V"],
case_insensitive=True,
help_command=None)
intents = discord.Intents().all()
intents = True
#client.event
async def on_ready():
print('Bot is Online! ;)')
servers = len(client.guilds)
members = 0
for guild in client.guilds:
members += guild.member_count - 1
await client.change_presence(activity=discord.Activity(
type=discord.ActivityType.watching,
name=f'{servers} servers and {members} members | %help'))
#client.command()
async def choosemem(ctx):
guild = ctx.guild
await ctx.send(f"{random.choice(guild.members).mention} has been chosen")
This Is the full code, including the status, and the intents.

You need to add the intents value in client= commands.Bot as well
intents = discord.Intents().all()
client = commands.Bot(command_prefix=['%', "v", "V"],
case_insensitive=True,
help_command=None,
intents = intents)

Related

appwrite list users search params

I am trying to use appwrite server sdk list users to get userid from an email.
The documentation says there is a search: option that can be used but no where does it say what the format of that String? is.
What is the format of the search: String? to only get a list of users whose email matches?
void main() { // Init SDK
Client client = Client();
Users users = Users(client);
client
.setEndpoint(endPoint) // Your API Endpoint
.setProject(projectID) // Your project ID
.setKey(apiKey) // Your secret API key
;
Future result = users.list(search: '<<<WHAT GOES HERE>>>');
}
:wave: Hello!
Thanks for bringing this question up, this is definitely not well documented, I'll note this down and try to make it clearer in the docs, but here's how you'd approach this in Dart:
final res = users.list(search: Query.equal('email',
'email#example.com'));
res.then((response) {
print(response.users[0].toMap());
}).catchError((error) {
print(error);
});
The Query object generates a query string, and works similar to how listDocument would work. The difference here is that it only takes a single query string instead of a list.

QnA Maker: How to count a specific answer in a session?

I have QnA Maker chatbot. I want to do that: If bot gives the DefaultNoAnswer 3 times in a session, I want to show different DefaultNoAnswer. How can I count the DefaultNoAnswers in QnAMakerBaseDialog ?
ex:
Client: asdaaasd
Bot: Sorry, Could you phrase your question differently?
Client: dsjhdsgjdsa
Bot:Sorry, Could you phrase your question differently?
Client: aasdjhajds
Bot: Sorry, I couldn't get the question. Send an email for detailed information.
I find the best way to handle this is with a conversation state variable. I have my default message set up in my helper (i.e. I have a helper file that makes the call to QnA Maker, checks the confidence, and sends a default message in case of low confidence or no answer). If you are using a similar case, you can increment your state variable there. If you are using QnA Maker's default answer directly, you still need to do some check on every result before sending the response to user. I haven't used that method, but I would probably just check the result for the default answer and increment the variable accordingly.
Here is a sample for the first case. I am assuming here that you are already familiar with managing user and conversation state.
var qnaResult = await QnAServiceHelper.queryQnaService(query, oldState);
if (qnaResult[0].score > MINIMUM_SCORE) {
const conversationData = await this.dialogState.get(step.context, {});
conversationData.defaultAnswerCounter = 0;
await this.conversationState.saveChanges(step.context);
var outputActivity = MessageFactory.text(qnaResult[0].answer);
} else {
const conversationData = await this.dialogState.get(step.context, {});
conversationData.defaultAnswerCounter += 1;
if (conversationData.defaultAnswerCounter <= 2) {
var outputActivity = defaultAnswer;
} else {
var outputActivity = escalationAnswer;
}
await this.conversationState.saveChanges(step.context);
}

Impersonation does not work in Microsoft Dynamics CRM - SYSTEM user is always used

I am investigating impersonation in Microsoft Dynamics CRM 2016 / Dynamics 365 organization service and I found that the code is always executed on behalf of the system user (SYSTEM).
I created a plugin that should execute requests on behalf of different users:
system user (SYSTEM)
default user
user specified in the plugin registration tool
user initiating the request
But the code is always executed on behalf of the system user (SYSTEM).
I tried not only to display an exception, but also to create records - they are also created on behalf of the system user (SYSTEM).
public class GetUsers : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var result = "";
var service1 = factory.CreateOrganizationService(null);
result += $"null = {GetUserInfo(service1)}";
var service2 = factory.CreateOrganizationService(Guid.Empty);
result += $"Guid.Empty ({Guid.Empty}) = {GetUserInfo(service2)}";
var service3 = factory.CreateOrganizationService(context.UserId);
result += $"UserId ({context.UserId}) = {GetUserInfo(service3)}";
var service4 = factory.CreateOrganizationService(context.InitiatingUserId);
result += $"InitiatingUserId ({context.InitiatingUserId}) = {GetUserInfo(service4)}";
throw new InvalidPluginExecutionException(result);
}
private static string GetUserInfo(IOrganizationService service)
{
var request = new WhoAmIRequest();
var response = (WhoAmIResponse)service.Execute(request);
var userId = response.UserId;
var user = service.Retrieve("systemuser", userId, new ColumnSet("fullname"));
var data = $"{userId} | {user.GetAttributeValue<string>("fullname")}{Environment.NewLine}";
return data;
}
}
I get this result:
null = 34248a5f-bf3e-4f3c-95c2-882424d25d37 | SYSTEM
Guid.Empty (00000000-0000-0000-0000-000000000000) = 34248a5f-bf3e-4f3c-95c2-882424d25d37 | SYSTEM
UserId (0a889533-cf85-e811-a21b-d47c6ef71c14) = 34248a5f-bf3e-4f3c-95c2-882424d25d37 | SYSTEM
InitiatingUserId (c69c88fb-4e41-e811-a214-83daa2756e35) = 34248a5f-bf3e-4f3c-95c2-882424d25d37 | SYSTEM
All requests are executed on behalf of the system user, although they must on behalf of different users.
Previously (in CRM 4.0-2013) it worked, but now it does not work. I tried on two different systems (different versions) - the result is the same.
Why?
Your example executes the WhoAmI request on behalf of several identities, but WhoAmI always returns the systemuserid of the authenticated user and since plugins are being executed by the SYSTEM account, its ID will always be returned.
Execute e.g. a Create request on entity Account and examine the attributes CreatedBy, CreatedOnBehalf and OwnerId.

How do you get a syncfusion custom adapter to work with the feathers socket.io client

feathers-client 2.3.0
syncfusion-javascript 15.3.29
I have been trying for awhile to create a syncfusion custom adapter for the feathers socket.io version of it's client. I know I can use rest to get data but in order for me to do offline sync I need to use the feathers-offline-realtime plugin.
Also I am using this in an aurelia project so I am using es6 imports with babel.
Here is a code snippet I have tried, I can post the whole thing if needed.
I am also not sure if just using the Adapter vs UrlAdapter is correct as I need sorting and paging to hit the server and not just to do it locally. I think I can figure that part out if I can at least get some data back.
Note: Per Prince Oliver I am adding a clarification to the question I need to be able to call any methods of the adapter as well besides just proccessQuery such as onSort. When the datagrid calls the onSort method I need to be able to call my api using the feathers socket.io client since it handles socket.io in a special manner for offline capabilities.
import io from 'socket.io-client';
import * as feathers from 'feathers-client';
const baseUrl = 'http://localhost:3030';
const socket = io.connect(baseUrl);
const client = feathers.default()
.configure(feathers.hooks())
.configure(feathers.socketio(socket));
const customers = client.service('customers');
export class FeathersAdapter {
feathersAdapter = new ej.Adaptor().extend({
processQuery: function (ds, query) {
let results
makeMeLookSync(function* () {
results = yield customers.find();
console.log(results);
});
The result is undefined. I have tried several other ways but this one seems like it should work.
REVISED CODE:
I am now getting data but also strange error as noted in the picture when I call
let results = await customers.find();
The process then continues and I get data but when the result variable is returned there is still no data in the grid.
async processQuery(ds, query) {
let baseUrl = 'http://localhost:3030';
let socket = io.connect(baseUrl);
let client = feathers.default()
.configure(feathers.hooks())
.configure(feathers.socketio(socket));
let customers = client.service('customers');
let results = await customers.find();
var result = results, count = result.length, cntFlg = true, ret, key, agg = {};
for (var i = 0; i < query.queries.length; i++) {
key = query.queries[i];
ret = this[key.fn].call(this, result, key.e, query);
if (key.fn == "onAggregates")
agg[key.e.field + " - " + key.e.type] = ret;
else
result = ret !== undefined ? ret : result;
if (key.fn === "onPage" || key.fn === "onSkip" || key.fn === "onTake" || key.fn === "onRange") cntFlg = false;
if (cntFlg) count = result.length;
}
return result;
The processQuery method in the DataManager is used to process the parameter which are set in the ej.Query like skip, take, page before fetching the data. Then the data is fetched asynchronously based on these parameters and fetched data is processed in processResponse method to perform operations like filtering or modifying. The processQuery function operates synchronously and it does not wait for the asynchronous process to complete. Hence the returned data from the API did not get bound on the Grid and throws undefined error.
So, if you are using the socket.io to fetch the data from the API, then the data can be directly bound to the Grid control using the dataSource property. Once the dataSource is updated with the result, it will be reflected in Grid automatically through two-way binding.
[HTML]
<template>
<div>
<ej-grid e-data-source.bind="gridData" e-columns.bind="cols"> </ej-grid>
</div>
</template>
[JS]
let baseUrl = 'http://localhost:3030';
let socket = io.connect(baseUrl);
let client = feathers.default()
.configure(feathers.hooks())
.configure(feathers.socketio(socket));
let customers = client.service('customers');
let results = await customers.find();
this.gridData = results; // bind the data to Grid

Linked-j.jar, getConnections() method return null alway

I am using linkedin-j.jar to get the get the LinkedIn Profile using getProfileById method but I am not able to fetch the Connections which comes from getConnection() method, it is always return null.
Can any one help me to come out this issue, below are the code snippet
Set<ProfileField> connectionFields = EnumSet.of(ProfileField.FIRST_NAME, ProfileField.LAST_NAME,ProfileField.CONNECTIONS)
Person person = client.methgetProfileById("id",connectionFields);
Connections conn = person.getConnections();
conn variable is coming as null.
Also I wanted to know that, why it is coming null.
Please check below code :
final LinkedInApiClientFactory factory = LinkedInApiClientFactory
.newInstance(BFF_CONSUMER_KEY, BFF_CONSUMER_SECRET);
final LinkedInApiClient client = factory
.createLinkedInApiClient(accessToken);
Set<ProfileField> fields = EnumSet.of(ProfileField.ID,
ProfileField.FIRST_NAME, ProfileField.LAST_NAME,ProfileField.CONNECTIONS);
Person profile = client.getProfileForCurrentUser(fields);
Person person = client.getProfileById(profile.getId(),fields);
Connections conn = person.getConnections();