Exemplo n.º 1
0
 def show_ungraceful_exit_popup(self):
     if get_dev():
         return
     popup = MOPopup('Ungraceful Exit', 'It seems MO closed unexpectedly last time.\n'
                     'Get the log from /kivy_logs, and send it to us for support.', 'OK')
     popup.size = [500, 200]
     popup.open()
Exemplo n.º 2
0
 def load(self):
     try:
         if self.loaded_icons and self.loaded_sprites:
             return
         if not self.loaded_sprites:
             self.load_sprites()
         if not self.loaded_icons:
             self.load_icons()
     except Exception as e:
         popup = MOPopup("Warning", "Something went wrong with " + self.name + "\n" + str(e), "OK")
         popup.open()
Exemplo n.º 3
0
 def get_disconnected(self, *args):
     if self.not_again_flag is False:
         self.ping_event.cancel()
         popup = MOPopup("Disconnected", "Seems you might be disconnected from IRC :(", "Okay.")
         popup.create_button("Don't show this again", False, btn_command=self.set_flag())
         popup.size = 800 / 2, 600 / 3
         popup.pos_hint = {'top': 1}
         popup.background_color = [0, 0, 0, 0]
         popup.open()
Exemplo n.º 4
0
 def on_login_clicked(self, *args):
     if self.username == '' or not self.is_username_valid():
         popup = MOPopup("Error", "Invalid username",
                         "Whatever you say, mate")
         popup.open()
         return
     if len(self.username) > 16:
         MOPopup("Error", "Username too long (max 16 characters)",
                 "Oh, okay").open()
         return
     self.set_username_as_last_used()
     self.set_current_user()
     self.create_irc_connection()
Exemplo n.º 5
0
 def create_item(self, name, description, image_link, user):
     message_len = len(name) + len(description) + len(image_link) + len(
         user)
     if message_len > 420:
         error_popup = MOPopup(
             "Character limit exceeded",
             "IRC has a character limit of roughly 500, please make"
             " sure your item's combined description, name, and image"
             " link don't exceed it.", "Close")
         error_popup.size = (900, 200)
         error_popup.open()
         return
     self.inventory.add_item(name, description, image_link, user)
Exemplo n.º 6
0
 def send_ooc(self):
     if len(self.ooc_input.text) > 400:
         popup = MOPopup("Warning", "Message too long", "OK")
         popup.open()
         return
     if self.ooc_input.text != "":
         Clock.schedule_once(self.refocus_text)
         msg = self.ooc_input.text
         user_handler: CurrentUserHandler = App.get_running_app(
         ).get_user_handler()
         connection_manager = user_handler.get_connection_manager()
         message_factory = App.get_running_app().get_message_factory()
         if self.ooc_input.text[0] == ";":
             message = message_factory.build_looc_message(
                 user_handler.current_loc.name, msg[1:])
         else:
             message = message_factory.build_ooc_message(msg)
         try:
             connection_manager.send_msg(message)
             connection_manager.send_local(message)
         except Exception as e:
             popup = MOPopup("Warning", "Something went wrong. " + str(e),
                             "OK")
             popup.open()
         self.ooc_input.text = ""
Exemplo n.º 7
0
 def send_message(self, *args):
     if len(self.text) > 250:
         popup = MOPopup("Warning", "Message too long", "OK")
         popup.open()
         return
     elif len(self.text) == 0 and not self.icon_change_spam:
         self.icon_change_spam = True
         Clock.schedule_once(self.enable_icon_change, 0.25)
         App.get_running_app().get_user_handler().send_icon()
         return
     main_scr = App.get_running_app().get_main_screen()
     Clock.schedule_once(main_scr.refocus_text)
     msg = escape_markup(self.text)
     if not self.message_is_valid(msg):
         return
     self.text = ""
     msg = self.extend_message(msg)
     if self.message_is_command(msg):
         try:
             self.handle_command(msg)
         except (AttributeError, IndexError) as e:
             Logger.warning(traceback.format_exc())
             return
     else:
         user_handler = App.get_running_app().get_user_handler()
         try:
             user_handler.send_message(msg)
         except Exception as e:
             popup = MOPopup("Warning", "Something went wrong. " + str(e),
                             "OK")
             popup.open()
Exemplo n.º 8
0
class MainScreenManager(ScreenManager):
    main_screen = ObjectProperty(None)
    irc_connection = ObjectProperty(None)
    connected = BooleanProperty(False)

    def __init__(self, **kwargs):
        super(MainScreenManager, self).__init__(**kwargs)
        self.popup_ = MOPopup("Connection", "Connecting to IRC", "K", False)

    def on_irc_connection(self, *args):
        """Called when the IRC connection is created"""

        self.set_handlers()
        self.main_screen.user = App.get_running_app().get_user()
        Clock.schedule_interval(self.process_irc, 1.0 / 60.0)
        self.popup_.open()

    def set_handlers(self):
        connection_manager = App.get_running_app().get_user_handler(
        ).get_connection_manager()
        self.irc_connection.on_join_handler = connection_manager.on_join
        self.irc_connection.on_users_handler = connection_manager.on_join_users
        self.irc_connection.on_disconnect_handler = connection_manager.on_disconnect

    def on_connected(self, *args):
        """Called when MO connects to the IRC channel"""

        self.unset_the_r_flag()
        self.popup_.dismiss()
        del self.popup_
        config = App.get_running_app().config
        sfx = SoundLoader.load('sounds/general/login.mp3')
        v = config.getdefaultint('sound', 'effect_volume', 100)
        App.get_running_app().play_sound(
            sfx, volume=App.get_running_app().exponential_volume(v))
        self.current = "main"
        self.main_screen.on_ready()
        connection_manager = App.get_running_app().get_user_handler(
        ).get_connection_manager()
        Clock.schedule_interval(connection_manager.update_chat, 1.0 / 60.0)

    def unset_the_r_flag(self):
        """Fixes being unable to receive private messages from other users"""

        username = App.get_running_app().get_user().username
        self.irc_connection.send_mode(username, "-R")

    def process_irc(self, dt):
        self.irc_connection.process()
        self.connected = self.irc_connection.is_connected()
Exemplo n.º 9
0
    def on_nicknameinuse(self, c, e):
        if len(App.get_running_app().get_user().username) < 16:
            c.nick(App.get_running_app().get_user().username + '_')
            App.get_running_app().get_user().username += '_'
            return
        temp_pop = MOPopup("Username in use", "Username in use, pick another one.", "OK")
        text_inp = TextInput(multiline=False, size_hint=(1, 0.4))
        temp_pop.box_lay.add_widget(text_inp)

        def temp_handler(*args):
            c.nick(text_inp.text)
            App.get_running_app().get_user().username = text_inp.text
        temp_pop.bind(on_dismiss=temp_handler)
        temp_pop.open()
Exemplo n.º 10
0
 def on_popup_error(popup, fields={}):
     epopup = MOPopup("Something went wrong",
                      "You entered invalid data.", "Aw, shucks.")
     epopup.open()
Exemplo n.º 11
0
    def on_music_play(self,
                      sender='Default',
                      url=None,
                      send_to_all=True,
                      track_name=None):
        if "dropbox" in self.url_input.text:
            self.url_input.text = self.url_input.text.replace(
                self.url_input.text[len(self.url_input.text) - 1], '1')
        if self.is_loading_music or not self.download:
            return
        self.is_loading_music = True
        main_screen = App.get_running_app().get_main_screen()
        # TODO : Variable user not being used, need to give it a purpose?
        user = App.get_running_app().get_user()
        if self.hide_title and sender == 'Default':
            track_name = "Hidden track"
        if url is None:
            if len(self.url_input.text) > 400:
                popup = MOPopup("Warning", "URL too long", "OK")
                popup.open()
                return
            url = self.url_input.text
        if track_name is not None:
            main_screen.music_name_display.text = "Playing: {}".format(
                track_name)
        else:
            main_screen.music_name_display.text = "Playing: URL Track"
        try:
            if send_to_all:
                self.url_input.text = ""
                connection_manager = App.get_running_app().get_user_handler(
                ).get_connection_manager()
                connection_manager.update_music(track_name, url)
                main_screen.log_window.add_entry("You changed the music.\n")
            if not any(s in url.lower()
                       for s in ('mp3', 'wav', 'ogg', 'flac',
                                 'watch')):  # watch is for yt links
                Logger.warning(
                    "Music: The file you tried to play doesn't appear to contain music."
                )
                self.is_loading_music = False
                return
        except MessageTooLong:
            self.url_input.text = ""
            temp_pop = MOPopup("Error playing music", "Link too long", "OK")
            temp_pop.open()

        def play_song(root):
            config_ = App.get_running_app().config
            music_path = "mucache"
            temp_dir = None

            if not config_.getboolean('sound', 'musiccache'):
                temp_dir: tempfile.TemporaryDirectory = tempfile.TemporaryDirectory(
                )
                music_path = temp_dir.name
            else:
                try:  # kebab
                    os.makedirs('mucache')
                except FileExistsError:
                    pass
            main_scr = App.get_running_app().get_main_screen()
            root.is_loading_music = True
            root.stop_all_tracks()
            if url.find(
                    "youtube") == -1:  # checks if youtube is not in url string
                try:  # does the normal stuff
                    r = requests.get(url, timeout=(5, 20))
                    """If no request were established within 5 seconds, it will raise a Timeout exception.
                       If no data was received within 20 seconds, it will also raise the same exception."""
                    r.raise_for_status()
                    """ Any HTTP Error that's between 400 and 600 will force the HTTPError exception to be raised.
                        root.is_loading_music was moved to be more global inside the method because if a http error is 
                        raised, the value of the variable won't be changed when it should be set to false. It also
                        removes the need to have to set it to false within each exception block."""
                except MissingSchema:
                    Logger.warning(
                        'Music Error: Invalid URL. Did you forget to add http:// at the beginning '
                        'by any chance?')
                    main_scr.music_name_display.text = "Error: Invalid URL. See warning logs for more details."
                    return
                except Timeout:
                    Logger.warning(
                        'Music Error: Request timed out. Either the server is not responding back or you '
                        'lost connection to internet.')
                    main_scr.music_name_display.text = "Error: Request timed out. See warning logs for more details."
                    return
                if r.ok:  # no errors were raised, it's now loading the music.
                    '''write a function for this?'''
                    songtitle = urllib.request.urlopen(
                        urllib.request.Request(
                            url,
                            method='HEAD',
                            headers={'User-Agent':
                                     'Mozilla/5.0'})).info().get_filename()
                    if songtitle is None:
                        songtitle = "temp"
                    elif track_name != None:
                        songtitle = track_name
                    else:
                        songtitle = os.path.basename(songtitle)
                        songtitle = os.path.splitext(songtitle)[
                            0]  # safer way to get the song title
                        songtitle = songtitle.encode('latin-1').decode(
                            'utf-8'
                        )  #nonascii names break otherwise, go figure
                    root.is_loading_music = True

                file = os.path.join(music_path, songtitle + '.mp3')
                if not os.path.isfile(file):
                    try:
                        f = open(file, mode="wb")
                    except OSError:
                        songtitle = 'Error Name'
                        f = open(file, mode="wb")
                    f.write(r.content)
                    f.close()
            else:
                try:
                    ytdl_format_options['outtmpl'] = os.path.join(
                        music_path, "%(title)s.mp3")
                    with youtube_dl.YoutubeDL(
                            ytdl_format_options
                    ) as ydl:  # the actual downloading
                        info = ydl.extract_info(url, download=False)
                        songtitle = ydl.prepare_filename(info)
                        songtitle = os.path.basename(songtitle)
                        songtitle = os.path.splitext(songtitle)[
                            0]  #safer way to get the song title
                        if not os.path.isfile(
                                os.path.join(music_path, songtitle + '.mp3')):
                            ydl.download([url])
                except Exception as e:
                    Logger.warning(traceback.format_exc())
                    if e is AttributeError:
                        main_scr.music_name_display.text = "Error: bad url"
                    else:
                        main_scr.music_name_display.text = "Error"
                    root.is_loading_music = False
                    return
            track = SoundLoader.load(
                os.path.join(music_path, songtitle + ".mp3"))
            track.loop = root.loop
            track.volume = App.get_running_app().exponential_volume(
                config_.getdefaultint('sound', 'music_volume', 100.0))
            root.track = track
            track.play()
            root.tracks.append(weakref.ref(track))
            root.is_loading_music = False
            if track_name != "Hidden track":
                if 'youtube' in url:
                    with open(
                            os.path.join(music_path,
                                         songtitle + '.mp3.info.json'),
                            'r') as f:
                        video_info = json.load(f)
                    main_scr.music_name_display.text = "Playing: {}".format(
                        video_info['fulltitle'])
                else:
                    main_scr.music_name_display.text = "Playing: " + songtitle

        threading.Thread(target=play_song, args=(self, ), daemon=True).start()
Exemplo n.º 12
0
 def __init__(self, **kwargs):
     super(MainScreenManager, self).__init__(**kwargs)
     self.popup_ = MOPopup("Connection", "Connecting to IRC", "K", False)
    def download_character(self, char_name, link, ver):
        try:
            if link.find("drive.google.com") == -1: #checks for google drive link
                try:
                    direct_link = link
                except Exception as e:
                    print("Error: " + e)
            else:
                try:
                    file_id = link.split('id=')
                    try:
                        id = file_id[1]
                        URL = "https://docs.google.com/uc?export=download"

                        session = requests.Session()

                        response = session.get(URL, params={'id': id}, stream=True)
                        token = self.get_confirm_token(response)

                        if token:
                            params = {'id': id, 'confirm': token}
                            response = session.get(URL, params=params, stream=True)

                        direct_link = response.url
                    except IndexError:
                        dlc_list = App.get_running_app().get_main_screen().character_list_for_dlc
                        char = char_name + '#' + link
                        dlc_list.remove(char)
                        self.dismiss()
                        temp_pop = MOPopup("Error downloading", "Can't download " + char_name, "OK")
                        temp_pop.open()
                        return
                except Exception as e:
                    print("Error: " + e)
            try:
                shutil.rmtree('characters/'+char_name)
            except Exception as e:
                print(e)
            path = 'characters/' + char_name + '.zip'
            r = requests.get(direct_link, allow_redirects=True)
            open(path, 'wb').write(r.content)
            with ZipFile(path) as zipArch:
                zipArch.extractall("characters")
            os.remove(path)
            dlc_list = App.get_running_app().get_main_screen().character_list_for_dlc
            char = char_name + '#' + link + '#' + ver
            dlc_list.remove(char)
            self.overwrite_ini(char_name, link, ver)
            KeyboardListener.refresh_characters()
            self.dismiss(animation=False)
            self.clean(char_name)
        except (KeyError, zipfile.BadZipFile, Exception) as e:
            print(e)
            self.dismiss()
            temp_pop = MOPopup("Error downloading", "Can't download " + char_name, "OK")
            temp_pop.open()
            return
        except Exception as e:
            print("Error 2: " + e)
        temp_pop = MOPopup("Download complete", "Downloaded " + char_name, "OK")
        temp_pop.open()
    def download_all(self):
        dlc_list = App.get_running_app().get_main_screen().character_list_for_dlc
        for text in dlc_list:
            arguments = text.split('#', 2)
            char = arguments[0]
            shared_link = arguments[1]
            try:
                if shared_link.find("drive.google.com") == -1:  # checks for google drive shared_link
                    try:
                        direct_link = shared_link
                    except Exception as e:
                        print("Error: " + e)
                else:
                    try:
                        file_id = shared_link.split('id=')
                        try:
                            id = file_id[1]
                            URL = "https://docs.google.com/uc?export=download"

                            session = requests.Session()

                            response = session.get(URL, params={'id': id}, stream=True)
                            token = self.get_confirm_token(response)

                            if token:
                                params = {'id': id, 'confirm': token}
                                response = session.get(URL, params=params, stream=True)

                            direct_link = response.url
                        except IndexError:
                            dlc_list = App.get_running_app().get_main_screen().character_list_for_dlc
                            char_link = char + '#' + shared_link
                            dlc_list.remove(char)
                            self.dismiss()
                            temp_pop = MOPopup("Error downloading", "Can't download " + char, "OK")
                            temp_pop.open()
                            return
                    except Exception as e:
                        print("Error: " + e)
                try:
                    shutil.rmtree('characters/' + char)
                except Exception as e:
                    print(e)
                path = 'characters/' + char + '.zip'
                r = requests.get(direct_link, allow_redirects=True)
                open(path, 'wb').write(r.content)
                with ZipFile(path) as zipArch:
                    zipArch.extractall("characters")
                os.remove(path)
                self.clean(arguments[0])
                char = arguments[0] + '#' + arguments[1] + '#' + arguments[2]
                self.overwrite_ini(arguments[0], arguments[1], arguments[2])
            except (KeyError, zipfile.BadZipFile, Exception) as e:
                print(e)
                try:
                    dlc_list = App.get_running_app().get_main_screen().character_list_for_dlc
                    char_link = char + '#' + shared_link
                    dlc_list.remove(char_link)
                except ValueError:
                    pass
                temp_pop = MOPopup("Error downloading", "Can't download " + char, "OK")
                temp_pop.open()
            except PermissionError:
                os.remove(path)
                shutil.rmtree('characters/' + char)
                temp_pop = MOPopup("Error downloading", "Can't download " + char + ". Permission Error, character folder deleted, try again.", "OK")
                temp_pop.open()
        App.get_running_app().get_main_screen().character_list_for_dlc = []
        KeyboardListener.refresh_characters()
        temp_pop = MOPopup("Download complete", "You downloaded everything.", "OK")
        temp_pop.open()
        self.dismiss(animation=False)
Exemplo n.º 15
0
 def process_roll(self):
     try:
         dice_game.process_input(self.command)
     except ValueError:
         temp_pop = MOPopup("Command error", "Rolling format is: xdy+z", "OK")
         temp_pop.open()