Discord bot profile application - discord

How to create an application on the user's profile with pycord(https://i.stack.imgur.com/vmt03.jpg)](https://i.stack.imgur.com/kMRc7.jpg)
I searched but did not find anything

Actually this is happens only mobile view.
What is causing this is "user.command".
#bot.user_command(name="name")
async def name(ctx, user: discord.Member):
await ctx.respond(user.name)

Related

I'm wondering how this is possible? Discord bot

I recently receive a 2 message in discord with invite link to server I received it from bot who doesn't share the same server with me or anything
How this is possible, I find some py codes but only work if the user and bot share same server
from discord.ext.commands import Bot, Greedy
from discord import User
bot = Bot(command_prefix='!')
#bot.command()
async def pm(ctx, users: Greedy[User], *, message):
for user in users:
await user.send(message)
bot.run("TOKEN")
How can I make one send messages to list of IDs not in same server?
Maybe the bot left the server after he sent the invite to everyone.
You could check if one of the bots was in the servers in the audit-log.
you could either get the user by id with the guild.get_member(id). That requires the user to be on that specific guild you try to get the user.
Or you can use bot.get_user(id) / await bot.fetch_user(id). There the bot tries to get the user. If found you can do sth with it else it will return None or raises the command Error UserNotFound.
A bot that has no mutal guild with a specific user cannot send a dm to them.
Also what purpuse is it to send dms to multiple users from a list?
Keep in mind that its against the Discord TOS to mass dm users without permissions. If they did not opt in sth to get dms I would not send random dms do multiple users.

Do you need firebase admin sdk when creating admin web?

I'm currently working on a small project using firebase. My team member is working on IOS and android while I'm trying to build a custom admin page using React.
In the app, users can signup with their phone and send a request for permission by attaching few documents.
I have to build an admin page to approve or deny these documents. For that I need to get list of all user from User Collection and view all the documents that was submitted and be able update user field 'isApproved' to true or false.
I was thinking of simply creating a new admin account directly in firebase and use that account to signin to admin page and perform the following actions (manipulate normal user info field). But I found out about firebase admin SDK. Do I need to use this in my case?
I may need to send push notifications to all users signed up and create user, update user, delete user account later on.
Give the situation should I use firebase admin SDK?
Can someone give me advice on how to set up the overall structure?
First things first, you should not use the Admin SDK on frontend. The Admin SDK has privileged access to all Firebase resources and does not follow any security rules either. You should always use Admin SDK in a secure environment like Firebase Cloud Functions or your own server.
I am not entirely sure what actions you need to perform while accepting/rejecting the documents. If you need to read/write a specific part of a database (which only a admin can access) then you can use Firebase security rules. You would have to add a Custom Claim to the admin user or store their UID in a database.
But if you need to do multiple things (maybe sending an email to user, doing some actions using 3rd party API), I'll recommend using a Cloud Functions with the Admin SDK.
How will that work?
You will have to create a Cloud Functions to accept/reject the documents.
When the admin accepts/rejects a document, you can pass details of that user (userID, document info and if the docs were accepted to the
cloud function) to the cloud function and process it over there.
The callable function may look like:
exports.verifyDocs = functions.https.onCall((data, context) => {
const {uid, token} = context.auth
if (!uid) return "Unauthorized"
if (!token.admin) return "Forbidden"
//The user is an admin
//Do database updates
//Any third party APIs
});
If you use callable functions, Firebase will automatically add auth info of the user calling that function. In the example above, I've assumed the user will have an admin custom claim but if you want to keep things simple based on UIDs you can do so by:
const adminUIDs = ["uid1", "uid2"]
if (!adminUIDs.includes(context.auth.uid)) return "Forbidden"
To call the function from your React app:
const verifyDocs = firebase.functions().httpsCallable('verifyDocs');
verifyDocs({ userID: "userID", text: messageText })
.then((result) => {
// Read result of the Cloud Function.
});
Any thing you pass in the function above will be available in your cloud functions in the 'data' parameter.

How to send sms messages from a React Native App programmatically ?

I want to be able to sent sms messages though my React Native app programatically in the background.
I know how to sent sms normally in the code, but the app keeps opening the default sms app, and that is not what i want.
The user should not push any buttons to sent the sms, because my goal is to notify a phonenumber every time the user is doing a particularly task in the app.
I have tried looking at Twilio, but they dont provide a api for React Native.
Does anybody know something about how I can do this ?
With the answer from kdenz, I followed a tutorial here: Seeting up a firebase function
This is my code for sending a request to Twilio, when the firebase database value 'visible' is changing.
import * as functions from 'firebase-functions';
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const twilio = require('twilio');
const accountSid = functions.config().twilio.sid;
const authToken = functions.config().twilio.token;
console.log(`Twilio account: ${accountSid}`);
const client = new twilio(accountSid, authToken);
const twilioNumber = 'xxx-xxx-xxx';
exports.textStatus = functions.database
.ref('/users/{userId}/data/visible')
.onUpdate(event => {
return admin.database()
.ref(`users/{userId}/data/`)
.once('value')
.then(snapshot => snapshot.val())
.then(user=> {
console.log(user[0]);
const longitude = user.longi;
const latitude = user.lati;
const phoneNumber = user.phone;
const textMessage = {
body: `See user position at Google: http://www.google.com/maps/place/${latitude},${longitude}`,
to: phoneNumber,
from: twilioNumber
}
return client.messages.create(textMessage);
})
.then(message => console.log(message.sid, 'success'))
.catch(err => console.log(err));
});
I think this is only possible with Android, as seen in this deprecated package https://www.npmjs.com/package/react-native-send-sms
For iOS, I don't think so, as seen in How to programmatically send a text message after the user has given permission?
To achieve what you want, you'll need a SMS service like Twilio. Then you can set up a server (Or a cloud function for minimal cost + easy maintainability) which receives API calls from your RN app, and sends the message to the desired recipient. You can then set up some security measures too, to prevent hackers from spamming the API.
Or if you don't care about security (Which I highly don't recommend), you can directly call Twilio send message API within your app, which is dangerous because hackers can easily extract your Twilio authorization token and use it to send messages for themselves.
On android, it is possible to send sms from user's number programmatically without user interaction.
But on IOS, the only way you can send an SMS without user interaction is to use an external provider such as Twilio; but the message will come from your server's number, not from the user.
I have already answered for same kind of question. Check this out
Is there anyway to send sms in background for both Android & IOS?

Python login feature and push notification

I need to create an admin login(admin for the website) and after admin login we need to send some push notification to the apps developed in ionic framework. I am bit confused from where i should start. I got a tutorial like https://thinkster.io/django-angularjs-tutorial#learning-django-and-angularjs which says how can i create users. Python provide me different option for login when i check but i am not sure which is the best method and which should i follow. Please help me on this. THe database connection we need is a pstgresql and the web script should be written in angularjs.
First of all, sending notifications to ios, and android is a bit different.
I was using couple of ready packages, but I found THIS one the most useful, and user-friendly.
In order to send notifications to android devices, you have to have generated GCM API KEY (Google Cloud Messaging)
Same goes with iOs, but you need a certificate there as well.
You can write a custom login method, link it, and inside send a push notification. Let's say (custom method, can be written better, just an example)
def api_login(request):
if request.method == 'POST':
username = request.data.get('username', None)
password = request.data.get('password', None)
if not username or not password:
return return_error(status.HTTP_400_BAD_REQUEST, "Login failed. Username or password missing or incorrect.")
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
# DO YOUR JOB HERE, SEND PUSH NOTIFICATION
# RETURN SOME MSG, TOKEN, OR ANYTHING :)
else:
return return_error(status.HTTP_401_UNAUTHORIZED, "Login failed. User is inactive")
return return_error(status.HTTP_401_UNAUTHORIZED, "Login failed. Login or password incorrect.")

Google App Engine User API with Google Accounts

I am trying to test my code in localhost before pushing to production. It's quite basic
def post(self):
user = users.get_current_user()
if user:
logging.warning('User nickname %s', user.nickname())
logging.warning('User email %s', user.email())
email = user.email()
else:
logging.warning('Go login again?')
users.create_login_url("/")
I am using a browser where I am already login into my gmail account. So I figure that should be sufficient, but it is not. In any case, it always takes me to the else block. But then the method users.create_login_url("/") does not seem to be doing anything: it never takes me to a login page; of course I am already logged in. So it's all confusing. How do I get this to work? Do I have to add something in my app.yaml? But this is for Google Accounts not for OpenID, which is the one that needs app.yaml attention I think.
users.create_login_url("/") will return the URL where the user will be ask to login. Your code must send/redirect the user to this URL.

Resources