I'm wanting to create a separate file of every member who joins the server and then be able to chose them randomly for a 'winner' command sorta thing - command

So I am using discord.js or Visual studio code or whatever. and I've made a random hug command. And I would like to be able to have it so that the one that gets hugged doesn't get # and it's just their name. I've successfully made a command similar to it, but i don't want to have to keep adding in names manually and theres no promise that the member won't change their name so it's not very reliable.
So I guess what's in my mind is having a file that automatically updates with users leaving or joining or changing their names and then to be able to call on them randomly without #ing them.
So does anybody know how to do this and how i can call on them?
I've done it with the #, and now im at where I manually write in every member's name but I know that is going to end up tedious and their name might change and I don't want to have to worry about them changing their name.
case 'randhug':
var user = message.guild.members.random();
let dismember = ["Klemon", "Second sofira", "CloudBot"]
let disresults = Math.floor((Math.random() * dismember.length));
message.channel.send(`${message.author} SURPRISE huggies you, ${dismember[disresults]}!!!!!`);
if (message.author.bot) return;
break;
The code I have now works, but isn't reliable in the sense that things change.

It sounds like you might find the tag or username properties of a User very valuable in this situation.
User.tag would return Username#1234.
User.username would return Username.
const member = message.guild.members.random();
message.channel.send(`${message.author} surprise huggies you, **${member.user.username}**!`)
.catch(console.error);

Related

Gatling session variable gets overwritten for multiple users. How to fix this?

So i am an absolute newbie to gatling and the documentation on their site is pretty meh. My scenario is that i have different users which execute one scenario each and during these scenarios they make requests and save the answer in a session variable which they need as a parameter for a following request during the same scenario. My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable. my idea was to set up a global counter which increments as soon as a new user is initialized and starts with his scenario and to append this counter to the session variable. is this possible and if so how do i do it? i bet there is a way better way to fix this behaviour but as i said i have zero experience with gatling and how its working.
my users look like this
user("singleUpload")
.behavior {
feed(applicationCredentials)
.exec(USingleUpload.singleUpload)
the scenarios like this
val singleUpload = exec(RUpload.post)
.exec(RShare.get)
.exec(RDownload.get)
.doIfEquals("${attachmentSingleUpload}", "attachment.jpg") {
exec(RThumbnailDownload.get)
}
.doIfEquals("${attachmentSingleUpload}", "attachment.png") {
exec(RThumbnailDownload.get)
}
.exec(RDelete.delete)
and the request like this:
val attachment = ("attachment", "${attachmentSingleUpload}")
val post = http("RUpload")
.post("/attachment/upload/")
.queryParam("share", "true")
.formUpload("attachment", s"attachments/${attachment._2}")
.header("x-api-key", "${apiKey}")
.header("x-app-id", "${appId}")
.check(status.is(200))
.check(jsonPath("$..pkey").exists.saveAs("pkey"))
val get = http("RShare")
.get("/attachment/share")
.queryParam("pkey", "${pkey}")
.header("x-api-key", "${apiKey}")
.header("x-app-id", "${appId}")
.check(status.is(200))
.check(jsonPath("$..skey").exists.saveAs("skey"))
for example: i make an upload and save the pkey which i then use in the request to get an skey. if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.
user("singleUpload")
.behavior {
There's neither user nor behavior methods in Gatling's API. If you really have this in your code, these are private customizations. Can't say what they do or if they're correct.
My problem is that i have multiple users running at the same time and these overwrite the session variable so that a user which started earlier refers to the wrong value in the session variable.
if user #2 is fast enough with his upload to overwritter the pkey variable in the session then user #1 uses a wrong pkey in his request.
This is absolutely impossible. Each virtual user has its own Session, isolated from the others'. You cannot store something in a given virtual user's Session and have another virtual user overwrite it. And there's absolutely zero chance of a bug in there.
I recommend that you reconsider how you came to this erroneous conclusion and investigate other possible explanations. This small piece you provided looks correct. Maybe you've simply uncovered a bug in your application and Gatling is just the messenger.
"the documentation on their site is pretty meh"
That's neither nice nor constructive. Maybe explaining what you think is lacking in the documentation? Have you gone through all of it? Have you checked the online courses?
Gatling sessions are isolated so overwritting is not really possible.
I am using saveAs in many simulations without any problems. The issue is somewhere else.

The best way to save game data in Unity that's secure & platfrom independent

I am looking for a way to save the users progress for my game, I am looking for something that can't be tampered with/modified. I would like to have to be able to be platform independent. And I would like it to be stored within the game files to the user can transfer their data to different computers (with a flash drive or something). (Correct me if I'm wrong in any area) But I believe because I need to to be secure and platform independent that removes player prefs from the equation. I know there is a way to save data by encrypting it with Binary, but I don't know how that works and if the user could transfer the data from computer to computer. Is there a better way of saving data? Is encrypting is through Binary the way to go? If so how would I do it? Thank you :) If you have any questions feel free to ask.
Edit: I understand nothing is completely secure, I'm looking for something that can stop the average user from going into a file, changing a float, and having tons and tons of money in game.
The previous answer mentiones two good methods for storing data (although there are still some quirks regarding writing files on different platforms), I'd like to add on to the subject of security, as mentioned in a comment here.
First of all, nothing is fully secure, there is always someone brighter out there that will find a flaw somewhere in your code, maybe unless you want full on crypto, which is not trivial with key management etc.
I understand from the question that he wants to prevent users from moving files between machines, or allow them to move the files between machines but seal them so that users cannot easily change data stored in them.
In either case, a trivial solution would work: generate a hashcode from your dataset, mangle with it a little bit (salt it or do whatever to jump to another hashcode). so you could have something like
{
"name"="john",
"score"="1234",
"protection"="043DA33C"
}
if the 'protection' field is a hashcode of "john1234", it will not match "john9999", hence if the user doesn't know how you salt your protection, you will be able to tell that the save has been tampered with
The first way to save data in unity is use PlayerPrefs, using for example:
PlayerPrefs.SetString("key","value");
PlayerPrefs.SetFloat("key",0.0f);
PlayerPrefs.SetInt("key",0);
PlayerPrefs.Save();
and for get, you only need
PlayerPrefs.GetString("key","default");
The second way and the way that permit you stored in a independent file is use serialization, my prefer way is a use the json file for it.
1) make a class that will store the data (not necessarily it need extends of monobehaviour:
[System.Serializable]
public class DataStorer {
public data1:String = "default value";
public data2:Int = 4;
public data3:bool = true;
....
}
and store it in another class with
DataStorer dataStorer = new DataStorer();
.... // some change in his data
string json = JsonUtility.ToJson(this, true);//true for you can read the file
path = Path.Combine(Application.persistantDataPath, "saved files", "data.json");
File.WriteAllText(path, json);
and for read the data
string json= File.ReadAllText(path);
DataStorer dataStorer = new DataStorer();
JsonUtility.FromJsonOverwrite(json, dataStorer);
and now you dateStorer is loaded with the data in your json file.
I found a link of data encryption tool, which is very helpful according to your need, as you want to secure data on device (nothing 100% secure), there are 3 mode to secure data, APP, Device and Encryption key, you can choose as per your need.
See this link, it may help you.
https://forum.unity.com/threads/data-encryption-tool-on-assets-store.738299/

Reading an SB-Messaging Send Port properties using the Microsoft.BizTalk.ExplorerOM makes a breaking change

I am working on a PowerShell script making use of the Microsoft.BizTalk.ExplorerOM to dynamically update the SB-Messaging SAS key for BizTalk Receive Locations and Send Ports. This is to enable us to roll the SAS keys for our Service Bus queues, and update BizTalk with the new keys as painlessly as possible.
I have this working correctly for Receive Locations, but Send Ports are giving me a different issue.
As soon as I read the PrimaryTransport properties of the Send Port, it seems that some change is made under the covers, that then prevents SaveChanges from working, instead throwing an "Invalid or malformed XML data exception".
This is compared to the the ReceiveLocation, where I can read any of its properties, and then SaveChanges successfully.
Note that in both of this cases, no changes have been made by me. I am simply doing a Read, and then a Save.
Can anyone offer any advice as to what could be causing the issue, and any possible solutions to try?
Had this very same issue, when using Powershell to replace values in ServiceBus ReceiveLocations & SendPorts.
The problem is with the none valid xml symbols in the TransportTypeData, which are converted when the script reads them out in the PS cmd.
All none valid xml symbols (such as the one occuring for Namespace value, ) need to be converted to amp, and if I'm not mistaken even double amp:ed.
Here's an example article showing examples on what I mean by "double amp:ed":
How do I escape ampersands in XML so they are rendered as entities in HTML?
Hope this make sense, and if not, then let me know and I'll give it another go.
Just tried doing this from C#, seems to work ok:
var root = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer() { ConnectionString = "Data Source=(local);Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;" };
var sendPort = root.SendPorts["xxxx.ServiceBusQueue"];
System.Diagnostics.Trace.TraceInformation(sendPort.PrimaryTransport.TransportTypeData);
sendPort .PrimaryTransport.TransportTypeData = sendPort.PrimaryTransport.TransportTypeData.Replace("RootManageSharedAccessKey", "MySharedAccessKey");
root.SaveChanges();

Grails: Radio button doesn't populate command obj when not selected

When I submit my form, if I do not select a value for my radio box then nothing is sent over to my command object for validation. I don't have issues with textFields or other input types.
class ApplicationCommand implements Validateable {
Map<String,String[]> questions = new LinkedHashMap<String,String[]>();
static constraints = {
questions validator: {val, obj, errors ->
for(String key : val.keySet()) {
errors.rejectValue("questions[${key}]",'required');
}
}
}
}
<g:radioGroup name="cmd.questions[1]" values="['Yes']" labels="['Yes']">
${it.radio}${it.label}
</g:radioGroup>
<g:textField name="cmd.questions[2]" />
With the above example, If i leave both fields empty and I submit I get the following
qusetions = [2: String[0]]
What I expect to see is
questions = [1: String[0], 2: String[0]]
Due to this issue, in my questions validator since key=1 is not populated I cannot validate it. The questions are dynamic all pulled from a DB so I cant hard-code anything in the validator such as if !questions.contains(1). Whatever data is populated into questions upon submission is what I have to assume the data is.
I have found 2 work-arounds, neither of which I like
1) Only for radio buttons, add a hidden field that will force a value to be populated if a radio is not selected. Horribly ugly
<g:hiddenField name="cmd.questions[1]" value="-" />
2) In my validator, I query the DB for all my questions and manually check for the existence of each one in the questions map. I want to avoid DB queries in my validators.
So while my 2 work-around options do work, I don't feel like I should have to resort to them.
I don't think this is a limitation of command objects or Grails; I think it's a limitation of HTML. I see the same question popping up in PHP.
The essential problem is that your command object doesn't know how many questions there are, but is responsible for making sure they are all there. I can think of a couple of (additional) ways to deal with this limitation:
The quick and easy way would be to put a single hidden input with the number of questions into your form. Also ugly, and open to alteration by the end-user.
The other option is to promote questions into a Domain so that the number of questions is known ahead of time, and is made available to your command object via a field or method. Then your command object can ask your questions, "How many are there supposed to be? Okay, did I get that many from the view?" This is similar to your #2 but without having to retrieve an entire collection and iterate it. This also opens up a path to perform further validation on each question (e.g., don't allow text into a numbers-only answer).
This does require hitting the DB, but it's the only way I can think of to validate the number of questions without relying on input from the view. The nice thing is that you can make it a very shallow hit, and hitting the DB can be very quick if you do it properly.

Apex Trigger - Attempting to send an email after an update

so I have just finished a degree in computing and have just started industry related employment and wow... we really don't seem to learn much at uni, just the bare basics.
Anyway, I am learning Apex and attempting to write my first trigger. The online tutorials are pretty unforgiving and I find that they seem to all miss out what my brain is lacking.
I am writing a trigger to automatically send an email to a specified address, the sending the email part is fine however I want to send in the email what has been changed and read as to whether it anything has been changed. What I have so far is as follows:
trigger Test1 on Account (after update) {
if(Trigger.isUpdate) {
//Commit current transaction, reserver email capacity
Messaging.reserveSingleEmailCapacity(1);
//Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<Messaging.SendEmailResult> results = new list<Messaging.SendEmailResult>();
//hold email address
String[] toAddresses = new String[] {'example#example.com'};
//Assign new address string
mail.setToAddresses(toAddresses);
//specify return ad (assuming as being sent from server)
mail.setReplyTo('pwitherby#gmail.com');
//sender name
mail.setSenderDisplayName('Mr Apex Tester');
//Subject Specification
mail.setSubject('Subjected to Learning');
//And... the content
mail.setPlainTextBody('You have just changed sumek... this really what you want....?')
if (!results.get(0).isSuccess())
System.debug('That didnt really work did it? Reason: ' + results.get(0).getErrors()[0].getMessage());
}
}
So my main questions that I cant find an answer for:
Will this work at current? so will this send this email if anything in the schema gets altered/updated?
I want to put in the email body what has been altered and what it has been changed to i.e "you have changed " + whatsChanged + " to " + telephoneNumber.
How do I listen for changes or is it already doing that?
Am I writing this to a decent standard or is it just messy code!
Sorry to waffle, it is my biggest downfall however I struggle to augment my questions without it!
You don't need to activate a trigger just writing it is enough.
You can access the changed new values Through Trigger.new (and Trigger.old for old values)
For Trigger documentation refer here
Maybe a workflow is more suitable to what you are trying to do.
And finally don't worry too much from the start about standard of the code (or beauty), it makes difference only when your code gets big anyway.