I've recently added this Discord bot to my server: https://github.com/critcola/discord-auto-grouping
It's working great and I've modified it slightly to ensure it creates a room based on the user's name, with a user limit and under a certain category in my server.
My last edit — which I can't seem to get my head around — is, when the channels are created, to add the user to the permissions and allow them full administrative rights on the channel only.
Below is what I've tried so far, it produces no errors it just doesn't do anything hence I'm now stumped!
Any help would be greatly appreciated.
// Check if the user entered a new channel.
if (member.voiceChannelID) {
const newChannel = member.guild.channels.get(member.voiceChannelID);
// If the user entered a game channel (prefixed with a game controller unicode emoji), group them into their own channel.
if (newChannel.name.startsWith(String.fromCodePoint('0x1F3AE'))) {
newChannel.clone(String.fromCodePoint('0x2501') + member.user.username + "'s Room", false)
.then(createdChannel => {
createdChannel.edit({
bitrate: 96000,
//position: newChannel.position + 0,
userLimit: 5,
parent: '409821646698971136'
})
//Set Permissions
.then(createdChannel.overwritePermissions(member.user.id,{'MANAGE_PERMISSIONS':true, 'MANAGE_CHANNELS':true}))
.then(createdChannel => {
member.setVoiceChannel(createdChannel)
.then(console.log('[' + new Date().toISOString() + '] Moved user "' + member.user.username + '#' + member.user.discriminator + '" (' + member.user.id + ') to ' + createdChannel.type + ' channel "' + createdChannel.name + '" (' + createdChannel.id + ') at position ' + createdChannel.position))
.catch(console.error);
})
.catch(console.error);
})
.catch(console.error);
}
}
You've made a little mistake. As MANAGE_PERMISSIONS is an invalid permission,
you need to use MANAGE_ROLES.
Related
The telegram bot must send a message to the user with force_reply active.
Inserting the link in the address bar works; the bot sends the message and the answer function is already active. The same link, generated by the code in Google Apps Script, does not work; the bot does not send anything.
Working link: (I replaced the id of my bot and the ID of the chat with BOT_TOKEN and CHAT_ID)
https://api.telegram.org/BOT_TOKEN/sendMessage?chat_id=CHAT_ID&text=force_replyTest&reply_markup={"force_reply":true}
code to generate the link
var url = "https://api.telegram.org/bot" + token;
function sendText(idChat,text) {
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup={"force_reply":true}');
Logger.log(response.getContentText());
}
if(text == "/p"){
sendText(idChat,"force_reply test");
}
Thank to #TheMaster
Work with this code
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup=' + encodeURIComponent('{"force_reply":true}'));
I would like to use Opbeat with Totaljs.
Do you have an idea how to use this tool with Total?
Thank you
While i haven't tried i believe the way to use Opbeat in Total.js is as follows
Place bellow code above require('total.js').http(....) or basicly at the very top of the file where this line require('total.js').http(....) is used.
// globally available OPBEAT can be used throughout the application
global.OPBEAT = require('opbeat').start({
// see documentations for more info
appId: '<app id>',
organizationId: '<org id>',
secretToken: '<token>'
});
require('total.js').http(....);
for logging errors or whatever you want you can use any of framework events
but since the framework doesn't emit event in case of error the easiest you can do is to overwrite bellow function, place the code bellow in some definition file
Framework.prototype.onError = function(err, name, uri) {
OPBEAT.captureError(err);
// original code can be left as is
console.log('======= ' + (new Date().format('yyyy-MM-dd HH:mm:ss')) + ': ' + (name ? name + ' ---> ' : '') + err.toString() + (uri ? ' (' + parser.format(uri) + ')' : ''), err.stack);
return this;
};
EDIT
one of these may be needed for showing the URL in Opbeat dashboard
F.on('request', function(req, res) {
OPBEAT.setTransactionName(req.method + ' ' + req.url);
});
F.on( 'controller', function( controller, name ) {
OPBEAT.setTransactionName(controller.route.method + ' ' + controller.route.url);
});
I am trying to share my custom link on facebook using this javascript function,
function postToFacebook(title, summary, image_url, U)
{
window.open('http://www.facebook.com/dialog/feed?app_id= ' + fb_app_id + '&display=popup&caption=' + title + '&description='+ summary + '&redirect_uri=' + encodeURIComponent('http://facebook.com') + '&link=' + encodeURI(U) + '&picture=' + image_url,'sharer','toolbar=0,status=0,width=548,height=325');
}
In my "U" parameter I have this link => "http://localhost:4000/rings/solitaire-rings/lst?utf8=%E2%9C%93&min_price=&max_price=&name=solitaire-rings&category=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&metal_white=on&commit=APPLY"
and when user clicks on the link which is shared on facebook , user should get redirected to this link. forget about root url i.e. localhost:4000, because on production environment its considering required url.
the problem is that whne i am sharing this url on facebook user is getting redirected to "http://localhost:4000/rings/solitaire-rings/lst?utf8", and its not taking care of further parameters which are "%E2%9C%93&min_price=&max_price=&name=solitaire-rings&category=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&metal_white=on&commit=APPLY"
basicaaly I supposed to get this URL "http://admin.velvetcase.com/rings/lst?utf8=%E2%9C%93&min_price=&max_price=&name=rings&fashion_type=false&search=&gallery_order=&new_arrival=&best_seller=&search_material_id[]=Diamond&commit=APPLY" , but when I am sharing mu URL on facebook I am getting this one "http://admin.velvetcase.com/rings/lst?utf8=%E2%9C%93&%3Bmin_price&%3Bmax_price&%3Bname=rings&%3Bfashion_type=false&%3Bsearch&%3Bgallery_order&%3Bnew_arrival&%3Bbest_seller&%3Bsearch_material_id[0]=Diamond&%3Bcommit=APPLY" , which is not giving e required output.
Here is what I did successfully
var sharingUrl = "https://www.facebook.com/dialog/feed?app_id="+ facebookAppID +
"&link=" + sharingUrl +
"&name=" + encodeURIComponent(title) +
"&caption=" + encodeURIComponent(caption) +
"&description=" + encodeURIComponent(content) +
"&picture=" + encodeURIComponent(thumb) +
"&redirect_uri=https://www.facebook.com";
window.open(sharingUrl);
For all parameters we need to use encodeURIComponent, but I try to not use encodeURIComponent for sharingUrl, it still works!
I have a little application that allows users to search for locations on a mac submit comments to a CartoDB SQL database (PostgreSQL) http://docs.cartodb.com/cartodb-platform/sql-api.html using an HMTL form, JavaScript and SQL (and a little PHP to make the API connection to CartoDB). It works great for vast majority of users, but some submissions are not coming through.
I have no idea why the SQL submissions are working sometimes and not others, works perfectly every time for me. Although I have tracked one issue down to Safari 5.1, but I think it must be happening in other browsers too. The main problem is I can't see any errors ANYWHERE, so it's impossible to track down.
So here are my questions:
1. Is there any way of catching SQL errors and preventing the form from being submitted?
2. Is there any way of seeing SQL errors so I can track down the problem?
Below is a snippet of the code I am using to submit the comments:
var tblName = "comment_collection"
var usrName = "***dney"
// FORM
$("#allSubmitBtn").click(function (e) {
//CHECK IF has a comment
if (!notEmpty(document.getElementById('description1'))) {
alert('Please enter a comment.');
return false;
}
if (!notEmpty(document.getElementById('latlongit1'))) {
alert('Sorry, there has been an error, please search for a location again.');
return false;
} else {
currentNeighborhood = $('#neighborhoodName1').val();
parcel = $('#parcel_id1').val();
address = $('#pre_address1').val();
userAddress = $('#UserAddress1').val();
phoneNum = $('#phone1').val();
emailAdd = $('#emailAddress1').val();
userType = $('#userType1').val();
otherUser = $('#otherUserType1').val();
currentDescription = $('#description1').val();
latlongy = $("input[name='latlongit1']").val();
explainType = $('#explainType').val();
currentProject = selectedCity.name;
commentType = new Array();
$("input:checkbox[name=commentType]:checked").each(function () {
commentType.push($(this).val());
});
var sql = "INSERT INTO " + tblName + " (the_geom, project, description, name,comment_address,parcel_id,phone_number,email_address,comment_type,comment_type_other,user_type,user_type_other,profile_address,flag,loved) VALUES (ST_SetSRID(ST_GeomFromGeoJSON('";
// var a = layer.getLatLng();
// console.log(a);
var sql2 = '{"type":"Point","coordinates":[' + latlongy + "]}'),4326),'" + currentProject + "','" + (currentDescription.replace(/'/g, "''")).replace(/"/g, "''") + "','" + (currentNeighborhood.replace(/'/g, "''")).replace(/"/g, "''") + "','" + address + "','" + parcel + "','" + phoneNum + "','" + emailAdd + "','" + commentType + "','" + explainType + "','" + userType + "','" + otherUser + "','" + userAddress + "','false','0')";
var pURL = sql + sql2;
console.log(pURL);
submitToProxy(pURL);
alert("Your Comments have been submitted");
return true;
}
});
here is the Github repo the tutorial is based off. Security is a MAJOR issue and is mentioned right off the bat with this tutorial. It is more of an illustration than anything, anyone implementing it should modify the scripts to be more secure.
Check out this pull request and try to create a solution from it. It addresses the issue to a degree. It moves more of the query into the PHP scripts and only allows field names in from the browser.
https://github.com/enam/neighborhoods/pull/4
This is incredibly dangerous/bad code. You're building sql on the client and sending it to the server to be executed. What's to stop someone from popping up their js console and doing submitToProxy('DROP DATABASE DATABASE()')?
Boom goes your site, boo hoo, too bad.
And even if you DON'T nuke this code from orbit, just to be sure it's really dead, and keep using it, you can't trap SQL exceptions, because they occur on the server, not in your client. At best your SERVER has to check for errors, and send back an appropriate message, e.g.
result = run_query(dangerous ql from user);
if (error occured) {
return json_encode('error' => true, 'reason' => 'someone set us up the bomb'));
} else {
return json_encode('error' => false, 'data' => query results);
}
and then your client-side ajax has to do
$.ajax(....
success: function (data) {
if (data.error) { alert('boom!'); }
else {... do stuff with data ...}
I am able to get the user's IP address in my website. Now i need his country, city, region using his IP i got.. I am trying Google's Geolocation API with the following code,
<div id="yourinfo"></div>
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAp04yNttlQq-7b4aZI_jL5hQYPm-xtd00hTQOC0OXpAMO40FHAxQMnH50uBbWoKVHwgpklyirDEregg"></script>
<script type="text/javascript">
if(google.loader.ClientLocation)
{
visitor_lat = google.loader.ClientLocation.latitude;
visitor_lon = google.loader.ClientLocation.longitude;
visitor_city = google.loader.ClientLocation.address.city;
visitor_region = google.loader.ClientLocation.address.region;
visitor_country = google.loader.ClientLocation.address.country;
visitor_countrycode = google.loader.ClientLocation.address.country_code;
document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
}
else
{
document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
}
</script>
Really this code is not working for me. It is executing the else part and displays Whoops!.
How to get the Geolocation of users. Any other idea let me know.
I already tried the following code which works well, but takes 6 Seconds of delay in free version. Later i came to know that google is giving this sevice for free.. So i am try on that.
http://services.ipaddresslabs.com/iplocation/locateip?key=SAK58RWP983694534K4Z&ip=".$ClientIP
Thank you in Advance
If you are happy to go with HTML5 you should visit this tutorial on geolocation.
use this on client side:
http://services.ipaddresslabs.com/iplocation/locateip?key=SAK58RWP983694534K4Z&ip=local-ip
its working fine with me.
By the way, the above key is blocked, you have to get new key instead.