diff --git a/data/scenario_resource.py b/data/scenario_resource.py new file mode 100644 index 0000000..210f7b9 --- /dev/null +++ b/data/scenario_resource.py @@ -0,0 +1,14 @@ + + +intro_text = "\n>$ You have been hacked\n>$ try to escape from the bad virus\n>$ " + +random_text = [ + "\n>$ All your base are belong to us\n>$ ", + "\n>$ The Answer to the Ultimate Question of Life, the Universe, and Everything is 42\n>$ ", + "\n>$ May the force be with you\n>$ ", + "\n>$ YOU SHALL NOT PASS!\n>$ ", + "\n>$ It's a trap!\n>$ ", + "\n>$ rm -rf /\n>$ ", + "\n>$ poweroff\n>$ ", + "\n>$ userdel $LOGNAME\n>$ " +] diff --git a/main.py b/main.py index d05fca0..ec6568a 100755 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import sys from term_utils import Term from command_helper import CommandHelper from trick import Trick +from scenario import intro class AnonymousGoose: @@ -13,7 +14,6 @@ class AnonymousGoose: self.should_exit = False self.stopped = False self.tricks = [] - self.log = [] self.keyboard_listener = pyxhook.HookManager() self.keyboard_listener.KeyUp = self.key_pressed self.keyboard_listener.HookKeyboard() @@ -26,7 +26,7 @@ class AnonymousGoose: for trick in self.tricks: trick.revert() - def run(self, disable_x): + def run(self): next_trick_time = 5 while not self.should_exit: try: @@ -35,7 +35,7 @@ class AnonymousGoose: time.sleep(1) next_trick_time -= 1 if next_trick_time <= 0: - trick = Trick.get_random_trick(not disable_x) + trick = Trick.get_random_trick() next_trick_time = trick.delay trick.run() if trick.is_reversible: @@ -46,10 +46,7 @@ class AnonymousGoose: def key_pressed(self, key): if key.Ascii == 27: self.should_exit = True - else: - self.log.append(key.key_pressed) - print(self.log) - + def stop(self): if self.stopped: return @@ -60,6 +57,7 @@ class AnonymousGoose: if __name__ == "__main__": disable_x = len(sys.argv) == 2 and sys.argv[1] == '-x' + intro() goose = AnonymousGoose() goose.run(disable_x) goose.stop() diff --git a/scenario.py b/scenario.py new file mode 100644 index 0000000..bded24e --- /dev/null +++ b/scenario.py @@ -0,0 +1,8 @@ +from data.scenario_resource import intro_text +from term_utils import Term +import time + +def intro(): + intro_terminal = Term() + intro_terminal.print_creepy(intro_text) + time.sleep(2) diff --git a/term_utils.py b/term_utils.py index 0eb79e6..e4e3e04 100644 --- a/term_utils.py +++ b/term_utils.py @@ -45,11 +45,14 @@ class Term: return False def print_creepy(self, msg): - with open(self.tty, "w") as file: - for char in msg: - file.write(char) - file.flush() - time.sleep(random.uniform(0, 0.2)) + try: + with open(self.tty, "w") as file: + for char in msg: + file.write(char) + file.flush() + time.sleep(random.uniform(0, 0.2)) + except PermissionError: + return False @staticmethod def print_all_creepy(msg): diff --git a/trick.py b/trick.py index 2e27386..bb54567 100644 --- a/trick.py +++ b/trick.py @@ -34,6 +34,7 @@ class Trick(ABC): from tricks.anim_ascii import AnimAsciiTrick from tricks.reflection import ReflectionTrick from tricks.rotation import RotationTrick + from tricks.random_message import RandomMessage tricks = [ LaughingGooseTrick, GlorifyGooseTrick, @@ -41,7 +42,8 @@ class Trick(ABC): ] x_tricks = [ ReflectionTrick, - RotationTrick + RotationTrick, + RandomMessage ] if keep_x: diff --git a/tricks/random_message.py b/tricks/random_message.py new file mode 100644 index 0000000..d036b7c --- /dev/null +++ b/tricks/random_message.py @@ -0,0 +1,24 @@ +from data.scenario_resource import random_text +from term_utils import Term +from trick import Trick +import random + +class RandomMessage(Trick): + @property + def name(self): + return "RandomMessage" + + @property + def delay(self): + return 5 + + @property + def is_reversible(self): + return False + + def revert(self): + pass + + def run(self): + randtext_term = Term() + randtext_term.print_creepy(random.choice(random_text))