Exemplo n.º 1
0
        public async Task meetupCommand(string meetup)
        {
            KnownMeetUp thisMup = GetThisMeetUp(meetup);

            EmbedBuilder b = new EmbedBuilder();


            if (thisMup != null)
            {
                b.WithTitle($"Meetup {thisMup.Name}");
                b.WithDescription($"The next meetup for {thisMup.Name}");
                b.WithColor(new Color(0, 170, 255));

                if (!string.IsNullOrEmpty(thisMup.URL))
                {
                    HttpWebRequest webClient = (HttpWebRequest)WebRequest.Create(thisMup.URL);
                    using (HttpWebResponse response = (HttpWebResponse)webClient.GetResponse())
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        {
                            List <MeetUpMeet> data = Newtonsoft.Json.JsonConvert.DeserializeObject <MeetUpMeet[]>(reader.ReadToEnd()).ToList();

                            if (data != null && data.Count > 0)
                            {
                                // Get Latest Meetup.
                                MeetUpMeet latest = data.OrderBy(m => m.local_date).OrderBy(m => m.local_time).ToList()[0];
                                b.AddInlineField("Name:", $"{latest.name}");
                                b.AddInlineField("Date:", $"{latest.local_date.ToShortDateString()} {latest.local_time}");
                                b.AddInlineField("Venue:", $"{latest.venue.name}");
                                b.AddInlineField("Address:", $"{latest.venue.address_1}, {latest.venue.city}, {latest.venue.localized_country_name}");
                            }
                            else
                            {
                                b.WithFooter("There are no Upcoming Meetups...");
                            }
                        }
                    }

                    b.WithUrl(thisMup.Link);
                }
                else
                {
                    b.WithDescription($"{thisMup.Name} does not use MeetUp, click the name to find out more...");
                    b.WithUrl(thisMup.Link);
                }
            }
            else
            {
                b.WithTitle($"Meetup not found");
                b.WithDescription($"The next meetup for [{meetup}] does not exist, try listing what meetups we can view...");
                b.WithColor(new Color(0, 170, 255));
            }

            await Context.Channel.SendMessageAsync("", false, b);
        }
Exemplo n.º 2
0
        public async Task StopBroadcastMUP(string meetup)
        {
            EmbedBuilder b          = null;
            KnownMeetUp  thisMeetup = GetThisMeetUp(meetup);

            if (thisMeetup != null)
            {
                string msg = string.Empty;

                MeetUpBroadcastService broadcastService = (MeetUpBroadcastService)Services.GetService(typeof(MeetUpBroadcastService));
                broadcastService.StopBroadcast(thisMeetup, Context.Channel, out msg);

                b = GetMsg("Stop Broadcast", msg);
            }
            else
            {
                b = GetErrorMsg($"{meetup} is not a known meet up.");
            }

            await Context.Channel.SendMessageAsync("", false, b);
        }
Exemplo n.º 3
0
        protected MeetUpMeet GetNextMeetup(KnownMeetUp thisMup, int offset = 0)
        {
            if (!string.IsNullOrEmpty(thisMup.URL))
            {
                HttpWebRequest webClient = (HttpWebRequest)WebRequest.Create(thisMup.URL);
                using (HttpWebResponse response = (HttpWebResponse)webClient.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        List <MeetUpMeet> data = Newtonsoft.Json.JsonConvert.DeserializeObject <MeetUpMeet[]>(reader.ReadToEnd()).ToList();

                        if (data != null && data.Count > 0)
                        {
                            // Get Latest Meetup.
                            MeetUpMeet latest = data.OrderBy(m => m.local_date).OrderBy(m => m.local_time).ToList()[offset];
                            return(latest);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        public async Task BroadcastMUP(string meetup, string duration)
        {
            EmbedBuilder b          = null;
            KnownMeetUp  thisMeetup = GetThisMeetUp(meetup);

            if (thisMeetup != null)
            {
                if (!string.IsNullOrEmpty(thisMeetup.URL))
                {
                    MeetUpBroadcastService broadcastService = (MeetUpBroadcastService)Services.GetService(typeof(MeetUpBroadcastService));
                    string   state;
                    TimeSpan ts;
                    MeetUpBroadCastTypeEnum type = MeetUpBroadCastTypeEnum.Reoccuring;

                    if (duration.ToLower().Substring(0, 6) == "before") // !mub name before02:00:00:00.000 in dd:hh:mm:ss.fff
                    {
                        type = MeetUpBroadCastTypeEnum.TimeSpanBefore;
                        ts   = TimeSpan.Parse(duration.Substring(6));         // How long before.
                    }
                    else if (duration.ToLower().Substring(0, 7) == "weekly:") // !mub name weekly:Monday
                    {
                        type = MeetUpBroadCastTypeEnum.Weekly;
                        // 0 = sun - 6 sat
                        int td       = (int)DateTime.Now.DayOfWeek;
                        int target   = (int)(DayOfWeek)Enum.Parse(typeof(DayOfWeek), duration.Substring(7));
                        int dayDelta = Math.Abs(target - td);
                        ts = DateTime.Now.AddDays(dayDelta) - DateTime.Now;   // Next Day to broadcast on from now
                    }
                    else if (duration.ToLower().Substring(0, 7) == "monthly") // !mub name monthly always first of the month.
                    {
                        type = MeetUpBroadCastTypeEnum.Monthly;
                        ts   = TimeSpan.Zero; // It's the 1st of every month
                    }
                    else
                    {
                        ts = TimeSpan.Parse(duration);
                    }

                    broadcastService.SetBroadcast(thisMeetup, Context.Channel, ts, type, out state);

                    if (!string.IsNullOrEmpty(state))
                    {
                        b = GetErrorMsg(state);
                    }
                    else
                    {
                        b = GetMsg("Broadcast Set", $"{type} Meet Up Broadcast set.");
                    }
                }
                else
                {
                    b = GetWarningMsg($"{thisMeetup.Name} meetup does not use MeetUp, so a broadcast can't be set.");
                }
            }
            else
            {
                b = GetErrorMsg($"{meetup} is not a known meet up.");
            }

            await Context.Channel.SendMessageAsync("", false, b);
        }