public static int GetDistancia(double origenLat, double origenLon, double destinoLat, double destinoLon) { string sURL; sURL = "http://maps.googleapis.com/maps/api/directions/json?origin="; sURL += origenLat.ToString().Replace(',', '.') + "," + origenLon.ToString().Replace(',', '.'); sURL += "&destination="; sURL += destinoLat.ToString().Replace(',', '.') + "," + destinoLon.ToString().Replace(',', '.'); sURL += "&sensor=false&mode=driving"; WebRequest wrGETURL; wrGETURL = WebRequest.Create(sURL); Stream objStream; objStream = wrGETURL.GetResponse().GetResponseStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GoogleData)); StreamReader objReader = new StreamReader(objStream); GoogleData data = (GoogleData)ser.ReadObject(objStream); if (data.routes == null || data.routes.Count == 0) { return(0); } return(data.routes[0].legs[0].distance.value); }
public bool saveGoogleDocument(GoogleData googleDataToSave) { bool success = false; try { var collection = GoogleMongoDB.GetCollection <BsonDocument>(MongoConsts.GOOGLE_BEST_RESULT_COLLECTION_NAME); var documentToInsert = googleDataToSave.ToBsonDocument(); collection.InsertOne(documentToInsert); success = true; } catch (Exception e) { Console.WriteLine("Error in AcMongoDAL.saveGoogleDocument e:{0}", e.Message); } return(success); }
public static async Task <string> GetGoogleEmailAsync() { string googleTokenString = await SecureStorage.GetAsync("GOOGLE"); string googleToken = JsonConvert.DeserializeObject <GoogleToken>(googleTokenString).AccessToken; HttpClient httpClient = new HttpClient(); HttpResponseMessage httpResponse = await httpClient.GetAsync($"https://www.googleapis.com/oauth2/v1/userinfo?access_token={googleToken}"); if (!httpResponse.IsSuccessStatusCode) { Debug.WriteLine($"Could not get GOOGLE email. Status: {httpResponse.StatusCode}"); } string data = await httpResponse.Content.ReadAsStringAsync(); GoogleData googleData = JsonConvert.DeserializeObject <GoogleData>(data); return(await Task.FromResult(googleData.Email)); }
public async Task <GoogleUserInfo> GetGoogleData(string code) { var gmailAuth = new GmailAuth(); gmailAuth.client_id = "client_id"; gmailAuth.client_secret = "client_secret"; gmailAuth.auth_uri = "https://accounts.google.com/o/oauth2/auth"; gmailAuth.token_uri = "https://accounts.google.com/o/oauth2/token"; var domainName = "http://localhost:5000"; // var responseType="code"; // var scope="https://www.googleapis.com/auth/userinfo.profile"; gmailAuth.redirect_uri = $"{domainName}/home/getgoogledata/sign-in"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response; var objJson = new GmailAuthHelper().GetUrlEncodedContent(gmailAuth, code); response = await client.PostAsync(gmailAuth.token_uri, objJson); if (response.IsSuccessStatusCode) { var jsondata = response.Content.ReadAsStringAsync().Result; GoogleData mytoken = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <GoogleData>(jsondata)); GoogleUserInfo userinfo = await GetUserDetails(mytoken.Access_token); return(userinfo); } else { return(null); } } }
void Response(string json) { if (string.IsNullOrEmpty(json)) { return; } GD = JsonUtility.FromJson <GoogleData>(json); if (GD.result == "ERROR") { ; } { print(GD.order + "를 싱핼 할 수 없습니다. 에러 메시지 : " + GD.msg); } print(GD.order + "을 실행했습니다. 메시지 :" + GD.msg); if (GD.order == "getValue") { ValueInput.text = GD.value; } }
public static async Task <bool> AdminCommands(SocketMessage message, CommandContext context, DiscordSocketClient client) { if (Validation.CheckCommand(message, "sweep")) { if (Validation.WordCountEqual(message, 2)) { try { int loops = 1; try { loops = System.Convert.ToInt32(DiscordFunctions.GetWord(message, 1)); } catch (FormatException) { } await DiscordFunctions.DeleteLastMessage(context, message.Channel.ToString()); for (int i = 0; i < loops; i++) { await DiscordFunctions.DeleteLastMessage(context, message.Channel.ToString()); await Task.Delay(1000); } DiscordFunctions.EmbedThisImage("Sweep Sweep", "", "https://i.imgur.com/UH1MPDz.gif", "green", context); } catch { } } else { // Warn the user it was a bad command DiscordFunctions.EmbedThis("Incomplete Command", "!sweep #", "red", context); } return(true); } else if (Validation.CheckCommand(message, "impersonate")) { // Make sure we have all parts if (Validation.WordCountGreater(message, 3)) { foreach (IGuildChannel channel in client.GetGuild(405513567681642517).TextChannels) { if (channel.Name == DiscordFunctions.GetWord(message, 1).Replace("#", "")) { string rebuiltstring = message.Content.Replace(DiscordFunctions.GetWord(message, 0) + " ", "").Replace(DiscordFunctions.GetWord(message, 1) + " ", ""); await client.GetGuild(405513567681642517).GetTextChannel(channel.Id).SendMessageAsync(rebuiltstring); break; } } } else { // Warn the user it was a bad command DiscordFunctions.EmbedThis("Incomplete Command", "!impersonate #channel message", "red", context); } return(true); } else if (Validation.CheckCommand(message, "deleteevent")) { // Make sure we have all parts if (Validation.WordCountEqual(message, 3)) { using (var db = new LiteDatabase(@"Events.db")) { try { var Events = db.GetCollection <Events>("Events"); var Event = Events.FindOne(x => x.Event.StartsWith(DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2))); Events.Delete(Event.Id); } catch { } } // Send a message saying we sre starting DiscordFunctions.EmbedThis("Event being deleted", message.Author.Mention + " deleting event " + DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2), "orange", context); await DiscordFunctions.CleanupEvent(context, message); DiscordFunctions.EmbedThis("Deletion Complete", "Event Deleted " + DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2), "green", context); } else { // Warn the user it was a bad command DiscordFunctions.EmbedThis("Incomplete Command", "!deleteevent EVENT YEAR", "red", context); } return(true); } else if (Validation.CheckCommand(message, "updaterules")) { foreach (IGuildChannel channel in client.GetGuild(486327167035244554).TextChannels) { if (channel.Name == "rules") { bool loop = true; while (loop) { try { IEnumerable <IMessage> messages = await client.GetGuild(486327167035244554).GetTextChannel(channel.Id).GetMessagesAsync().FlattenAsync(); foreach (var messagefound in messages) { await messagefound.DeleteAsync(); await Task.Delay(1000); } if (messages.Count() == 0) { loop = false; } } catch { loop = false; } } foreach (var stringmes in GoogleData.ReadRules()) { if (stringmes == "\n") { // None } else { await client.GetGuild(486327167035244554).GetTextChannel(channel.Id).SendMessageAsync(stringmes); } await Task.Delay(500); } break; } } return(true); } else if (Validation.CheckCommand(message, "giant")) { DiscordFunctions.EmbedThisImage("Better watch out!", "", "https://pbs.twimg.com/media/EHnQ_CcWoAAMhqG?format=png&name=360x360", "red", context); return(true); } else if (Validation.CheckCommand(message, "everyone")) { // Make sure we have all parts if (Validation.WordCountEqual(message, 2)) { using (var db = new LiteDatabase(@"Config.db")) { var DatabaseConfig = db.GetCollection <DatabaseConfig>("DatabaseConfig"); var Config = DatabaseConfig.FindOne(x => x.Id.Equals(1)); if (DatabaseConfig.Count() == 0) { Config.Everyonetag = false; Config.TweetChannel = "announcements"; DatabaseConfig.Insert(Config); } if (DiscordFunctions.GetWord(message, 1).ToLower() == "true") { Config.Everyonetag = true; DatabaseConfig.Update(Config); DiscordFunctions.EmbedThis("Value Updated", message.Author.Mention + " Value is now true", "green", context); } else if (DiscordFunctions.GetWord(message, 1).ToLower() == "false") { Config.Everyonetag = false; DatabaseConfig.Update(Config); DiscordFunctions.EmbedThis("Value Updated", message.Author.Mention + " Value is now false", "green", context); } else { DiscordFunctions.EmbedThis("Error", message.Author.Mention + " Value must be true or false", "red", context); } } } else { DiscordFunctions.EmbedThis("Incomplete Command", "!everyone true", "", context); } return(true); } else if (Validation.CheckCommand(message, "tweetchannel")) { // Make sure we have all parts if (Validation.WordCountEqual(message, 2)) { using (var db = new LiteDatabase(@"Config.db")) { var DatabaseConfig = db.GetCollection <DatabaseConfig>("DatabaseConfig"); var Config = DatabaseConfig.FindOne(x => x.Id.Equals(1)); if (DatabaseConfig.Count() == 0) { Config.Everyonetag = false; Config.TweetChannel = "announcements"; DatabaseConfig.Insert(Config); } Config.TweetChannel = DiscordFunctions.GetWord(message, 1).ToLower().Replace("#", ""); DatabaseConfig.Update(Config); DiscordFunctions.EmbedThis("Tweet Channel Update", "New tweet channel is" + DiscordFunctions.GetWord(message, 1), "green", context); } } else { DiscordFunctions.EmbedThis("Incomplete Command", "!tweetchannel #channel", "red", context); } return(true); } else if (Validation.CheckCommand(message, "debuglist")) { using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); var results = Guardians.FindAll(); Console.WriteLine("-----------------Guardians-------------------"); foreach (UserData user in results) { Console.WriteLine(user.Id + " " + user.DiscordUsername + " " + user.Team + " " + user.Event + " " + user.GroupMeGroup + " " + user.GroupMeTime); } } using (var db = new LiteDatabase(@"Events.db")) { var Events = db.GetCollection <Events>("Events"); var results = Events.FindAll(); Console.WriteLine("-----------------Events-------------------"); foreach (Events user in results) { Console.WriteLine(user.Id + " " + user.Event); } } return(true); } else if (Validation.CheckCommand(message, "reload")) { // Load the Database from google sheets List <UserData> users = GoogleData.ReadDB(); using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); List <string> ErrorList = new List <string>(); foreach (UserData user in users) { UserData Guardian = null; foreach (var Guard in Guardians.FindAll()) { if (Guard.DiscordUsername.ToLower().Trim().Contains(user.DiscordUsername.ToLower().Trim())) { Guardian = Guard; break; } } if (Guardian != null) { Guardian.Team = user.Team; Guardians.Update(Guardian); } else { if (user.DiscordUsername.Contains("#")) { try { using (var eventdb = new LiteDatabase(@"Events.db")) { var Events = eventdb.GetCollection <Events>("Events"); var Event = Events.FindAll(); Guardian = new UserData { Event = Event.First().Event, DiscordUsername = user.DiscordUsername, Team = user.Team, Authenticated = false }; Guardians.Insert(Guardian); } } catch { ErrorList.Add(user.DiscordUsername); } } else { ErrorList.Add(user.DiscordUsername); } } } if (ErrorList.Count != 0) { string csv = String.Join(",\n", ErrorList.Select(x => x.ToString()).ToArray()); System.IO.File.WriteAllText("/opt/files/ErrorUsers.csv", csv); await message.Channel.SendFileAsync("/opt/files/ErrorUsers.csv", "Users with Errors"); System.IO.File.Delete("/opt/files/ErrorUsers.csv"); } // Index document using a document property Guardians.EnsureIndex(x => x.DiscordUsername); } // Notify the user the DB reload has completed DiscordFunctions.EmbedThis("The DB has been reloaded", "", "green", context); return(true); } else if (Validation.CheckCommand(message, "withdraw")) { // Make sure we have all parts if (Validation.WordCountEqual(message, 2)) { if (DiscordFunctions.GetWord(message, 1).Contains("#")) { using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); UserData Guardian = Guardians.FindOne(x => x.DiscordUsername.ToLower().StartsWith(DiscordFunctions.GetWord(message, 1).ToLower())); if (Guardian != null) { bool found = false; Console.WriteLine(Guardian.DiscordUsername); foreach (var user in await context.Guild.GetUsersAsync()) { if (user.Username.ToLower() + "#" + user.Discriminator.ToString() == Guardian.DiscordUsername.ToLower()) { if (user.RoleIds.Count == 2) { foreach (var role in user.Guild.Roles) { if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id)) { await user.RemoveRoleAsync(role); } } foreach (var role in user.Guild.Roles) { if (role.Name.ToLower() == "global entry") { await user.AddRoleAsync(role); } } } else { List <string> eventroles = new List <string>(); foreach (var role in user.Guild.Roles) { if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id)) { if (role.Name.ToLower().Contains("guardian-austin-")) { eventroles.Add(role.Name); } } } List <int> eventnumber = new List <int>(); foreach (string role in eventroles) { eventnumber.Add(Int32.Parse(role.ToLower().Replace("guardian-austin-", ""))); } foreach (var role in user.Guild.Roles) { if (user.Guild.EveryoneRole != role && user.RoleIds.Contains(role.Id)) { if (role.Name.ToLower() == "guardian-austin-" + eventnumber.Max().ToString()) { await user.RemoveRoleAsync(role); } } } } DiscordFunctions.EmbedThis("Users Removed", "Please remember to remove the user from the sheet", "orange", context); found = true; break; } } Guardians.Delete(Guardian.Id); if (found == false) { DiscordFunctions.EmbedThis("Unable to locate user in Discord", "User Removed from Database", "green", context); } } else { DiscordFunctions.EmbedThis("Error", "User is not a guardian", "red", context); } } } else { DiscordFunctions.EmbedThis("Incomplete Command", "!withdraw user", "", context); } } return(true); } else if (Validation.CheckCommand(message, "newevent")) { // Make sure we have all parts if (Validation.WordCountEqual(message, 3)) { using (var db = new LiteDatabase(@"Events.db")) { var Events = db.GetCollection <Events>("Events"); Events Eventexists = Events.FindOne(x => x.Event.ToLower().StartsWith(DiscordFunctions.GetWord(message, 1).ToLower() + "-" + DiscordFunctions.GetWord(message, 2).ToLower())); if (Eventexists == null) { Events NewEvent = new Events { Event = DiscordFunctions.GetWord(message, 1) + "-" + DiscordFunctions.GetWord(message, 2) }; Events.Insert(NewEvent); } } // Send a message saying we sre starting DiscordFunctions.EmbedThisImage("New Event Generating", "Please give it a few minutes (5+) to complete", "https://i.imgur.com/Gyn3f3T.gifv", "orange", context); await NewEventBuilder.GenerateRolesAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2))); await NewEventBuilder.GenerateCategoriesAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2))); await NewEventBuilder.GenerateChannelsAsync(context, DiscordFunctions.GetWord(message, 1), Convert.ToInt32(DiscordFunctions.GetWord(message, 2))); DiscordFunctions.EmbedThisImage("New Event Generating Complete", "", "", "green", context); } else { // Warn the user it was a bad command DiscordFunctions.EmbedThis("Incomplete Command", "!newevent EVENT YEAR", "", context); } return(true); } else if (Validation.CheckCommand(message, "cleardb")) { using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); foreach (var Guardian in Guardians.FindAll()) { if (Guardian.Authenticated == false) { Guardians.Delete(Guardian.Id); } } } DiscordFunctions.EmbedThis("Users Removed", "", "orange", context); return(true); } else if (Validation.CheckCommand(message, "unauthenticated")) { using (var db = new LiteDatabase(@"Guardians.db")) { var Guardians = db.GetCollection <UserData>("Guardians"); List <string> UnauthenticatedList = new List <string>(); var Guardianlist = Guardians.FindAll(); foreach (var Guardian in Guardianlist) { if (Guardian.Authenticated == false) { UnauthenticatedList.Add(Guardian.DiscordUsername); } } string csv = String.Join(",\n", UnauthenticatedList.Select(x => x.ToString()).ToArray()); System.IO.File.WriteAllText("/opt/files/unauth.csv", csv); await message.Channel.SendFileAsync("/opt/files/unauth.csv", "Unauthenticated users"); System.IO.File.Delete("/opt/files/unauth.csv"); } return(true); } return(false); }
void Debug(string json) { if (string.IsNullOrEmpty(json)) { return; } GD = JsonUtility.FromJson <GoogleData>(json); if (GD.result == "ERROR") { print(GD.order + "을 실행할수 없습니다" + GD.msg); debuggingText.text = (GD.order + "을 실행할수 없습니다" + GD.msg); loadingPanel.SetActive(false); return; } print(GD.order + "을 실행했습니다" + GD.msg); debuggingText.text = (GD.order + "을 실행했습니다" + GD.msg); if (GD.order == "register") { registerPanel.SetActive(false); } if (GD.order == "getValue") { if (GD.type == "3") { playerNickName = GD.value; NM.nickNameInput.text = GD.value; nickInputComplete = true; CompleteAllCheck(); } else if (GD.type == "5") { playercolor = GD.value; string[] result = playercolor.Split(new string[] { "." }, System.StringSplitOptions.None); colorManager.playerMainColors[0] = int.Parse(result[0]); colorManager.playerMainColors[1] = int.Parse(result[1]); colorManager.playerMainColors[2] = int.Parse(result[2]); colorManager.playerBoosterColors[0] = int.Parse(result[3]); colorManager.playerBoosterColors[1] = int.Parse(result[4]); colorManager.playerBoosterColors[2] = int.Parse(result[5]); GetValue(6); } else if (GD.type == "6") { string[] result = GD.value.Split(new string[] { "." }, System.StringSplitOptions.None); NM.playerIconCode = int.Parse(result[0]); GM.playerLv = int.Parse(result[1]); GM.exp = float.Parse(result[2]); GM.maxExp = float.Parse(result[3]); GM.money = int.Parse(result[4]); GM.reinPoint = int.Parse(result[5]); GM.codyMainCode = int.Parse(result[6]); GM.codyBodyCode = int.Parse(result[7]); GM.codyParticleCode = int.Parse(result[8]); DTM.damageSkinCode = int.Parse(result[9]); GM.abilityCode[0] = int.Parse(result[10]); GM.abilityCode[1] = int.Parse(result[11]); GM.abilityCode[2] = int.Parse(result[12]); GM.abilityValue[0] = int.Parse(result[13]); GM.abilityValue[1] = int.Parse(result[14]); GM.abilityValue[2] = int.Parse(result[15]); AM.abilityGrade[0] = int.Parse(result[16]); AM.abilityGrade[1] = int.Parse(result[17]); AM.abilityGrade[2] = int.Parse(result[18]); GM.plainLv = int.Parse(result[19]); RM.upgradeInfo[0] = int.Parse(result[20]); RM.upgradeInfo[1] = int.Parse(result[21]); RM.upgradeInfo[2] = int.Parse(result[22]); RM.upgradeInfo[3] = int.Parse(result[23]); RM.upgradeInfo[4] = int.Parse(result[24]); RM.upgradeInfo[5] = int.Parse(result[25]); JM.jobCode = int.Parse(result[26]); int index = 27; for (int i = 0; i < challengeManager.challenge.Length; i++) { if (result[index] == "True") { challengeManager.challenge[i] = true; } else { challengeManager.challenge[i] = false; } index++; } NM.loginPlayerIconImage.sprite = NM.icons[NM.playerIconCode]; movePlayerinfoComplete = true; CompleteAllCheck(); } } if (GD.order == "NicknameCheck") { if (GD.makeNick == "yes") { canMakeNick = true; } else { canMakeNick = false; } if (!canMakeNick)//이미닉이있다 { GetValue(3); makeNickComplete = true; CompleteAllCheck(); return; } //없다면 닉네임창에 놔둠; loadingPanel.SetActive(false); } if (GD.order == "login") { playernum = int.Parse(GD.numOfPlayer); GM.loginPanel.SetActive(false); CheckNickname(); GetValue(5); } if (GD.order == "NicknameSameCheck") { if (GD.result == "OK") { makeNickComplete = true; nickInputComplete = true; CompleteAllCheck(); } else { print("닉네임 중복됨"); } } if (GD.order == "checkSameId") { regIdInput.interactable = true; if (GD.result == "OK") { idCheck = true; isCurrentId.sprite = currentSprites[0]; idText.text = "사용가능한 아이디 입니다."; } else { idCheck = false; isCurrentId.sprite = currentSprites[1]; idText.text = "중복된 아이디 입니다."; } } }