def show_ungraceful_exit_popup(self): 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()
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.5) 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: print(e) 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()
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()
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 self.set_username_as_last_used() self.set_current_user() self.create_irc_connection()
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()
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: direct_link = 'https://drive.google.com/uc?export=download&id=' + file_id[ 1] 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) 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: dlc_list = App.get_running_app().get_main_screen( ).character_list_for_dlc char_link = char + '#' + shared_link dlc_list.remove(char_link) temp_pop = MOPopup("Error downloading", "Can't download " + char, "OK") temp_pop.open() App.get_running_app().get_main_screen().character_list_for_dlc = [] KeyboardListener.refresh_characters() self.dismiss(animation=False)
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)
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()
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) sfx.volume = v / 100 sfx.play() sfx.seek(0) 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()
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()
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 connection_manager = App.get_running_app().get_user_handler( ).get_connection_manager() message_factory = App.get_running_app().get_message_factory() message = message_factory.build_ooc_message(msg) connection_manager.send_msg(message) connection_manager.send_local(message) self.ooc_input.text = ""
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: direct_link = 'https://drive.google.com/uc?export=download&id=' + file_id[ 1] 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) 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: self.dismiss() temp_pop = MOPopup("Error downloading", "Can't download " + char_name, "OK") temp_pop.open() except Exception as e: print("Error 2: " + e)
def send_message(self, *args): if len(self.text) > 400: popup = MOPopup("Warning", "Message too long", "OK") popup.open() 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): self.handle_command(msg) else: user_handler = App.get_running_app().get_user_handler() user_handler.send_message(msg)
def on_music_play(self, sender='Default', url=None, send_to_all=True, track_name=None): 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 try: #kebab os.makedirs('mucache') except FileExistsError: pass if not config_.getboolean('sound', 'musiccache'): try: shutil.rmtree('mucache/') os.makedirs( 'mucache' ) #deleting all files instead of nuking dirs breaks youtube jsons when playing the same song. except FileNotFoundError: #can't delete what doesn't exist os.makedirs('mucache') except PermissionError: print("Cannot clear music cache due to permission error.") except Exception as e: print(e) main_scr = App.get_running_app().get_main_screen() track = root.track root.is_loading_music = False # at first, nothing is being loaded, so we set this variable to False. if track is not None and track.state == 'play': track.stop() 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" 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 if not os.path.isfile('mucache/' + songtitle + '.mp3'): f = open("mucache/" + songtitle + ".mp3", mode="wb") f.write(r.content) f.close() else: try: 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('mucache/' + songtitle + '.mp3'): ydl.download([url]) root.is_loading_music = True # no exceptions were raised, so it's loading the music. except Exception as e: root.is_loading_music = False if e is AttributeError: main_scr.music_name_display.text = "Error: bad url" else: main_scr.music_name_display.text = "Error" return track = SoundLoader.load("mucache/" + songtitle + ".mp3") track.volume = config_.getdefaultint('sound', 'music_volume', 100) / 100 track.loop = root.loop track.play() root.track = track root.is_loading_music = False if track_name != "Hidden track": if 'youtube' in url: with open('mucache/' + 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, )).start()
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()
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)