├── src ├── checked.example.txt ├── logs │ ├── log.example.txt │ └── violations_log.example.txt ├── checked_comments.example.txt ├── rudeness │ ├── checked.example.txt │ └── rudeness_log.example.txt ├── users │ └── users.example.json ├── data-analyzation │ ├── checked.example.txt │ └── words.example.json ├── violations │ └── violations.example.json ├── __main__.py ├── utils.py ├── config.example.py ├── text_recognition.py ├── blacklist.py ├── analyze.py ├── rude_phrases.py ├── message.py └── main.py ├── docs ├── _config.yml ├── assets │ ├── images │ │ ├── bg.jpg │ │ └── bg2.jpg │ └── css │ │ └── style.css └── index.html ├── requirements.txt ├── CHANGELOG.md ├── TODO.org ├── .gitignore ├── CODE_OF_CONDUCT.md ├── README.md └── LICENSE /src/checked.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/logs/log.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/checked_comments.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/rudeness/checked.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/users/users.example.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /src/logs/violations_log.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/rudeness/rudeness_log.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-dinky -------------------------------------------------------------------------------- /src/data-analyzation/checked.example.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/data-analyzation/words.example.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /src/violations/violations.example.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | praw 2 | pytesseract 3 | opencv-python 4 | Pillow 5 | tqdm 6 | tesseract-ocr -------------------------------------------------------------------------------- /docs/assets/images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecsw/MemePolice_bot/HEAD/docs/assets/images/bg.jpg -------------------------------------------------------------------------------- /docs/assets/images/bg2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecsw/MemePolice_bot/HEAD/docs/assets/images/bg2.jpg -------------------------------------------------------------------------------- /src/__main__.py: -------------------------------------------------------------------------------- 1 | from main import main 2 | 3 | if __name__ == "__main__": 4 | main() 5 | else: 6 | pass 7 | -------------------------------------------------------------------------------- /src/utils.py: -------------------------------------------------------------------------------- 1 | def log_to_file(text): 2 | file = open("./logs/log.txt", "a") 3 | file.write(text + "\n") 4 | file.close() 5 | -------------------------------------------------------------------------------- /src/config.example.py: -------------------------------------------------------------------------------- 1 | # This is for reddit 2 | client_id = '' 3 | client_secret = '' 4 | username = '' 5 | password = '' 6 | user_agent = '' 7 | -------------------------------------------------------------------------------- /docs/assets/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-image: url("../images/bg2.jpg"); 3 | background-size: auto; 4 | } 5 | 6 | #top { 7 | margin-top: 25px; 8 | } 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | * **03/14/18** - Justin 4 | * Violation in the main message 5 | * Replies to rude users 6 | * Logging errors to file 7 | * Logging violations to file 8 | * Logging rudeness replies to file 9 | 10 | * **03/14/18** - Sandy 11 | * Added the mentions feature 12 | 13 | * **2/25/18** - Sandy 14 | * Fixed skipping some downvoted comments 15 | 16 | * **2/15/18** - Justin 17 | * Added offending user tracking 18 | * Fixed skipping of already checked memes 19 | * Added example files for required locally stored files 20 | 21 | * **2/4/18** - Justin 22 | * Added Regular Expression for image types 23 | * Fixed titles not being recognized 24 | * Added try/catch around text_recognition 25 | * Added *requirements.txt* 26 | * Misc file changes 27 | -------------------------------------------------------------------------------- /src/text_recognition.py: -------------------------------------------------------------------------------- 1 | from urllib import request 2 | import os, sys 3 | import pytesseract 4 | import cv2 5 | from PIL import Image 6 | 7 | 8 | def text_recognition(post): 9 | meme_name = "temp" # We would just call all the temporary images as "temp" 10 | request.urlretrieve(post.url, filename=meme_name) # Here we are downloading the appropriate image (png, jpg, jpeg, bmp) 11 | image = cv2.imread(meme_name) # We load up the image using opencv 12 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Turning the image to grayscale 13 | gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1] # Making a threshold for the image, text will be more apparent 14 | gray = cv2.medianBlur(gray, 3) # Adding some blur, useful for really noisy images 15 | filename = "{}-ocr.png".format(meme_name) # Making the temporary, ready file for text recognition 16 | cv2.imwrite(filename, gray) # Now, we will save the image 17 | img = Image.open(filename) # Open the processed image with pillow 18 | recognized_text = pytesseract.image_to_string(img).encode('utf-8') # As a means of exceptions, need to read out as UTF-8, so no encoding errors would occur 19 | os.remove(filename) # Deleting all temporary image 20 | os.remove(meme_name) 21 | return recognized_text # Returns the recognized text in UTF-8 encodign and with capital and lower letters 22 | -------------------------------------------------------------------------------- /src/blacklist.py: -------------------------------------------------------------------------------- 1 | # This is a dictionary of all banned words. 2 | # If MemePolice_bot find these words in submission's title or text from media 3 | # The ban method will be called 4 | 5 | illegal_memes = [ 6 | "399", # Chair memes 7 | "but can you do this", 8 | "tide pod", 9 | "do u know", # Ugandan memes 10 | "da wae", 11 | "uganda", 12 | "slippy", # Slippy memes 13 | "skiddadle", 14 | "skadoodle", 15 | "skidd", 16 | "skado", 17 | "your dick is now a noodle", 18 | "is now a noodle", 19 | "your dick", 20 | "upvote if", # Upvote begging 21 | "upvote so", 22 | "upvote to", 23 | "upvote this", 24 | "please upvote", 25 | "if this post", 26 | "if this submission", 27 | "when this post", 28 | "when this submission", 29 | "pls upvote", 30 | "upvote pls", 31 | "please like", 32 | "pls like", 33 | "up vote", 34 | "can we hit", 35 | "fbi agent", # FBI agent memes 36 | "fbi", 37 | "original content", # Self-explanatory 38 | "dead people", 39 | "suicide forest", 40 | "toucha", # Spaghet memes. They are just old. 41 | "flat earth", # Flat Earth thing. Dead from 05.04.18. 42 | "why like this", 43 | "not like this", 44 | "if earth is round", 45 | "if earth is not flat" 46 | ] 47 | -------------------------------------------------------------------------------- /src/analyze.py: -------------------------------------------------------------------------------- 1 | import praw 2 | import json 3 | import time 4 | import re 5 | 6 | from utils import log_to_file 7 | 8 | replace_chars = ['"', '.', ';', ':', '?', '!', '*', '+', '-', '(', ')', '[', ']', '{', '}', '>', '<', ',', '^', '@', 9 | '$', '%', '&', '_', '=', '\n', '|', '\\', "#", '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] 10 | 11 | 12 | def parse_comment(c): 13 | try: 14 | file = open("./data-analyzation/words.json", 'r') 15 | words_json = json.loads(file.read()) 16 | file.close() 17 | 18 | print("Reading comment " + c.id + " at " + time.strftime("%b %d, %Y - %I:%M:%S") + " by " + str(c.author)) 19 | 20 | body = str(c.body.encode('utf-8')) 21 | 22 | for w in body.split(' '): 23 | word = str(w.encode('utf-8')) 24 | 25 | if "http" in word or "/u/" in word or "/r/" in word or "\\" in word: 26 | continue 27 | 28 | for ch in replace_chars: 29 | word = word.replace(ch, '') 30 | 31 | if word is not "" and word is not " " and word is not "'" and word is not "," and word is not '\n' and word[0] is not "'": 32 | 33 | if word in words_json.keys(): 34 | words_json[word] = int(words_json.get(word)) + 1 35 | else: 36 | words_json[word] = 1 37 | 38 | file = open("./data-analyzation/words.json", 'w') 39 | file.write(json.dumps(words_json)) 40 | 41 | file.close() 42 | 43 | except: 44 | log_to_file("Failed to read words.json at " + time.strftime("%b %d, %Y - %I:%M:%S")) 45 | return 46 | -------------------------------------------------------------------------------- /src/rude_phrases.py: -------------------------------------------------------------------------------- 1 | # This is a dictionary of rude phrases in which to reply. 2 | # If a user replies to MemePolice_bot with one of these phrases, the bot will reply to them. 3 | # Note: The word list is an example, as to not have a file of obscenities on the GitHub 4 | 5 | import random 6 | import praw 7 | 8 | rude_list = [ 9 | "frick you", 10 | "you suck", 11 | "go to heck" 12 | ] 13 | 14 | rude_reply_list = [ 15 | "Well that's pretty rude.", 16 | """**Police sounds** 17 | 18 | You've been charged with being a complete ass. 19 | """, 20 | """**Police sounds** 21 | 22 | You've been charged cussing on a ***Christian Subreddit***. 23 | """, 24 | "Well I'm sorry you feel that way.", 25 | "I know you are but what am I?", 26 | "You're literally spending time and effort to insult a bot on the internet.", 27 | "This is a ***Christian Subreddit***. Please keep your cussing to a minimum.", 28 | """Careful with the cussing, kids could be watching. 29 | 30 | ***Christian Subreddit*** 31 | """, 32 | "***Christian Subreddit***", 33 | "Do you kiss your mother with that mouth?" 34 | ] 35 | 36 | 37 | def rudeness_reply(c): 38 | write_to_rude_log("Replied to " + c.author + "'s comment: " + c.body + "\n\n") 39 | c.reply(rude_reply_list[random.randint(0, len(rude_reply_list) - 1)]) 40 | 41 | 42 | def alt_rudeness_reply(c, text): 43 | write_to_rude_log("Replied to " + c.author + "'s comment: " + c.body + " with " + text + "\n\n") 44 | c.reply(text) 45 | 46 | 47 | def write_to_rude_log(text): 48 | file = open("./rudeness/rudeness_log.txt", "a") 49 | file.write(text) 50 | file.close() 51 | -------------------------------------------------------------------------------- /TODO.org: -------------------------------------------------------------------------------- 1 | #+TITLE: u/MemePolice_bot todo list 2 | #+DATE: 17-03-2018 3 | 4 | 5 | * TODO [#A] Fix the strange mentions bug where it just does not respond 6 | * TODO [#B] Make blacklist.py into one .json file 7 | 8 | * We can arrange words in different sections 9 | 10 | | Topic | Keywords | 11 | |----------------+---------------------| 12 | | Chair memes | 399 | 13 | | | chair | 14 | | | but can you do this | 15 | |----------------+---------------------| 16 | | Ugandan memes | do you know | 17 | | | do u know | 18 | | | da wae | 19 | |----------------+---------------------| 20 | | Upvote begging | upvote so | 21 | | | upvote to | 22 | | | upvote please | 23 | |----------------+---------------------| 24 | | ... | ... | 25 | 26 | * If the post is a fanart and upvote beggar, do not trigger the bot. 27 | 28 | | OK | NOT OK | 29 | |-------------------------------------------+------------------------------------------------| 30 | | Upvote so pewds would see my fanart! | Please upvote so pewds would see his handshake | 31 | |-------------------------------------------+------------------------------------------------| 32 | | Please like my work! I tried really hard! | Upvote so we all can laugh at this | 33 | |-------------------------------------------+------------------------------------------------| 34 | | ... | ... | 35 | 36 | * TODO [#C] Organizing all the collected data in one .sql 37 | 38 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Meme Police 4 | 5 | 6 | 8 | 9 | 10 | 11 | 13 | 14 | 16 | 17 | 18 | 19 | 20 |
21 | 22 |
23 |

Meme Police Bot

24 |

Police sounds.

25 | 26 | Source Code 27 | README 28 | Changelog 29 | Code of Conduct 30 | License 31 | 32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /src/message.py: -------------------------------------------------------------------------------- 1 | # This is the message that all users who violated MemePolice will receive under their submissions 2 | 3 | message = """ *Police sounds* 4 | 5 | Good day, sir/ma'am! You have been visited by the **Meme Police!** 6 | 7 | I see that you posted an illegal meme on r/PewdiepieSubmissions, *for example: chair memes, tide pods, uganda memes, skiddadle skadoodle, upvote begging, and etc.* 8 | 9 | Your violation was the keyword: '%VIOLATION%'. 10 | 11 | Do not publish old or overused memes here because **only fresh and skrattar memes are allowed!** 12 | 13 | You have been warned and please, do not make the same mistake twice. **I do NOT remove posts.** 14 | ______________________ 15 | 16 | ^(I am an AI bot in this subreddit and my duty is to keep order and peace. Sometimes I can be wrong and if I am wrong, please reply or downvote. You can fix it by contributing to the code! Meme Police is real.) 17 | 18 | [Source code](https://github.com/thecsw/MemePolice_bot) | [Subreddit](https://reddit.com/r/MemePolice_bot) 19 | """ 20 | 21 | mention = """ *Police sounds* 22 | 23 | Good day, sir! Thank you for calling us! 24 | 25 | We hope that the post is illegal and we didn't get bamboozled. 26 | """ 27 | 28 | damages = [ # This array holds responses for comments like "no u" 29 | "*roblox damage sound*", 30 | "*minecraft damage sound*", 31 | "*fortnite damage sound*", 32 | "*the sniper 2 damage sound*", 33 | "*pubg damage sound*" 34 | ] 35 | 36 | 37 | bl_message = """ *Police sounds* 38 | 39 | Good day, sir/ma'am! You have been visited by the **Meme Police!** 40 | 41 | I see that you posted a FUCKING AWESOME meme on r/PewdiepieSubmissions 42 | 43 | **T-Series ain't nothing but a Bitch Lasagna** 44 | 45 | ______________________ 46 | 47 | ^(I am an AI bot in this subreddit and my duty is to keep order and peace. Sometimes I can be wrong and if I am wrong, please reply or downvote. You can fix it by contributing to the code! Meme Police is real.) 48 | 49 | [Source code](https://github.com/thecsw/MemePolice_bot) | [Subreddit](https://reddit.com/r/MemePolice_bot) 50 | """ 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # My emacs backup files 2 | .saves 3 | 4 | # Our checklists 5 | words.json 6 | checked.txt 7 | checked_comments.txt 8 | 9 | # Byte-compiled / optimized / DLL files 10 | __pycache__/ 11 | *.py[cod] 12 | *$py.class 13 | 14 | # C extensions 15 | *.so 16 | 17 | # Error logging 18 | log.txt 19 | 20 | # Config file 21 | config.py 22 | 23 | # Analyzation files 24 | words.json 25 | checked.txt 26 | 27 | # User files 28 | users.json 29 | 30 | # Rudeness files 31 | rudeness_log.txt 32 | 33 | # Violation files 34 | violations.json 35 | violations_log.txt 36 | 37 | # Actual Rude Phrase File 38 | rude_phrases_real.py 39 | 40 | 41 | # Temp OCR files 42 | temp 43 | temp-ocr.png 44 | 45 | # Distribution / packaging 46 | .Python 47 | env/ 48 | build/ 49 | develop-eggs/ 50 | dist/ 51 | downloads/ 52 | eggs/ 53 | .eggs/ 54 | lib/ 55 | lib64/ 56 | parts/ 57 | sdist/ 58 | var/ 59 | wheels/ 60 | *.egg-info/ 61 | .installed.cfg 62 | *.egg 63 | 64 | # PyInstaller 65 | # Usually these files are written by a python script from a template 66 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 67 | *.manifest 68 | *.spec 69 | 70 | # Installer logs 71 | pip-log.txt 72 | pip-delete-this-directory.txt 73 | 74 | # Unit test / coverage reports 75 | htmlcov/ 76 | .tox/ 77 | .coverage 78 | .coverage.* 79 | .cache 80 | nosetests.xml 81 | coverage.xml 82 | *.cover 83 | .hypothesis/ 84 | 85 | # Translations 86 | *.mo 87 | *.pot 88 | 89 | # Django stuff: 90 | *.log 91 | local_settings.py 92 | 93 | # Flask stuff: 94 | instance/ 95 | .webassets-cache 96 | 97 | # Scrapy stuff: 98 | .scrapy 99 | 100 | # Sphinx documentation 101 | docs/_build/ 102 | 103 | # PyBuilder 104 | target/ 105 | 106 | # Jupyter Notebook 107 | .ipynb_checkpoints 108 | 109 | # pyenv 110 | .python-version 111 | 112 | # celery beat schedule file 113 | celerybeat-schedule 114 | 115 | # SageMath parsed files 116 | *.sage.py 117 | 118 | # dotenv 119 | .env 120 | 121 | # virtualenv 122 | .venv 123 | venv/ 124 | ENV/ 125 | 126 | # Spyder project settings 127 | .spyderproject 128 | .spyproject 129 | 130 | # Rope project settings 131 | .ropeproject 132 | 133 | # mkdocs documentation 134 | /site 135 | 136 | # mypy 137 | .mypy_cache/ 138 | 139 | 140 | # PyCharm 141 | /.idea 142 | /__pycache__ 143 | 144 | 145 | # OS X DS_Store files 146 | .DS_Store 147 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at sagindyk.urazayev@protonmail.ch. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MemePolice_bot 2 | 3 | This is a reddit bot that finds old or not funnny posts and images on r/PewdiepieSubmissions subreddit. When the bot finds an illegal meme, the OP will receive the message below. This bot was created as a serious project (joke-ish) and later on was improved a little bit. 4 | 5 | 6 | 7 | ## Getting Started 8 | 9 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. 10 | 11 | ### Prerequisites 12 | 13 | What things you need to install the software and how to install them 14 | 15 | ```bash 16 | sudo pip install praw 17 | sudo pip install python-opencv 18 | sudo pip install pytesseract 19 | sudo pip install tesseract-ocr 20 | sudo pip install Pillow 21 | sudo pip install tqdm 22 | ``` 23 | 24 | OR 25 | 26 | ``` 27 | pip install --upgrade -r requirements.txt 28 | ``` 29 | 30 | [praw](https://github.com/praw-dev/praw) is Python Reddit API Wrapper. This will be the main and only package to connect to Reddit's API and extract desired data. 31 | 32 | [python-opencv](https://pypi.python.org/pypi/opencv-python) is used for image transformations and computer vision problems. 33 | 34 | [pytesseract](https://pypi.python.org/pypi/pytesseract) is a python wrapper for Google's Tesseract-OCR. 35 | 36 | [Pillow](https://pillow.readthedocs.io/en/latest/) is the Python Imaging Library by Fredrik Lundh and Contributors. 37 | 38 | [tqdm](https://pypi.python.org/pypi/tqdm) is used for fancy progress bars. 39 | 40 | ### Other dependencies 41 | 42 | Tesseract engine should be installed on a local machine to run the text recognition properly. We will also install the tesseract OCR trained languages for better accuracy and we will install only the English packages. For more information about other languages, please refer to tesseract's official [repository on Github](https://github.com/tesseract-ocr/tesseract). 43 | 44 | #### Linux 45 | 46 | ##### Debian, Ubuntu (aptitude) 47 | ``` 48 | sudo apt-get install tesseract-ocr 49 | sudo apt-get install tesseract-ocr-eng 50 | ``` 51 | 52 | ##### Arch Linux (pacman) 53 | 54 | ``` 55 | sudo pacman -S tesseract 56 | sudo pacman -S tesseract-data-eng 57 | ``` 58 | 59 | #### Mac OS 60 | 61 | ##### Homebrew 62 | 63 | ``` 64 | brew install tesseract 65 | ``` 66 | 67 | I don't know what about other distros. I think tesseract-ocr is included in all package managers. 68 | 69 | If you want to compile the tesseract engine by yourself, please refer to the [official guides.](https://github.com/tesseract-ocr/tesseract/wiki/Compiling). 70 | 71 | ### Installing 72 | 73 | The only thing that needs to be done before execution is the config profile. In the config profile you should fill your Reddit API details. 74 | 75 | For that please follow these steps 76 | 77 | ```bash 78 | git clone https://github.com/thecsw/MemePolice_bot 79 | cd MemePolice_bot 80 | mv example.config.py config.py 81 | nano config.py 82 | ``` 83 | 84 | After filling out the details, save and exit. You're done with installation. 85 | 86 | ## Deployment 87 | 88 | Remove the word **'example'** from the title of all files with it. 89 | 90 | Just run this 91 | 92 | ```bash 93 | python __main__.py 94 | ``` 95 | 96 | That is everything. All illegal memes shall be found and OPs should be punsihed. 97 | 98 | ## Source code 99 | 100 | The code is heavily commented and all the important modules are being separated into different files. Looks pretty, dunno. 101 | 102 | Here is a short description of all the source files 103 | 104 | - `analyze.py` - Heavy file on analyzing comments and filling them in needed files. 105 | - `blacklist.py` - Contains all the banned keywords that will trigger the bot to respond. 106 | - `config.example.py` - Just the PRAW (OAuth) credentials for bot initialization. 107 | - `main.py` - The main script that processses everything and has the main loop with threads. 108 | - `message.py` - Different messages that bot will send to users. 109 | - `rude_phrases.py` - Bot's responses to rude replies. 110 | - `text_recognition.py` - Returns text read from an image. 111 | - `utils.py` - Just the logging and other technical stuff. 112 | - `__main__.py` - The file that should be executed. 113 | 114 | Here is a short description of .json and .txt files that we have 115 | 116 | - `./users/users.json` - this is a list of offenders with the number of illegal content posted 117 | - `./data-analyzation/checked.txt` - stores checked comments. 118 | - `./data-analyzation/words.json` - sotres words and their respective frequency. 119 | - `./rudeness/checked.txt` - stores old rude replies. 120 | - `./rudeness/rudeness_log.txt` - stores the logs and other "rude" data. 121 | - `./violations/violations.json` - stores all the violations. 122 | - `./logs/log.txt` - stores errors and other debug information. 123 | - `./logs/violations_log.txt` - debug data for violations. 124 | 125 | ## Built With 126 | 127 | - [praw](https://github.com/praw-dev/praw) is Python Reddit API Wrapper. This will be the main and only package to connect to Reddit's API and extract \ 128 | desired data. 129 | - [python-opencv](https://pypi.python.org/pypi/opencv-python) is used for image transformations and computer vision problems. 130 | - [pytesseract](https://pypi.python.org/pypi/pytesseract) is a python wrapper for Google's Tesseract-OCR. 131 | - [Pillow](https://pillow.readthedocs.io/en/latest/) is the Python Imaging Library by Fredrik Lundh and Contributors. 132 | - [tqdm](https://pypi.python.org/pypi/tqdm) is used for fancy progress bars. 133 | 134 | ## Authors 135 | 136 | - **Sagindyk Urazayev** - *Initial work* - [thecsw](https://github.com/thecsw) 137 | - **Justin Schwaitzberg** - *Rewriting, structuring, and adding new features* - [Schwaitz](https://github.com/Schwaitz) 138 | 139 | ## Acknowledgments 140 | 141 | - Fedora tip to Justin Schwaitzberg for greatly contributing to the code, structuring it and making it fancier. 142 | 143 | ## License 144 | 145 | This project is licensed under the The GNU General Public License - see the [LICENSE.md](https://github.com/thecsw/MemePolice_bot/blob/master/LICENSE) file for details) explains it pretty well. 146 | -------------------------------------------------------------------------------- /src/main.py: -------------------------------------------------------------------------------- 1 | # Fill your Reddit and Telegram API in example.config.py and rename it to config.py 2 | 3 | ''' 4 | __ __ ____ _ _ 5 | | \/ | ___ _ __ ___ ___ | _ \ ___ | (_) ___ ___ 6 | | |\/| |/ _ \ '_ ` _ \ / _ \ | |_) / _ \| | |/ __/ _ \ 7 | | | | | __/ | | | | | __/ | __/ (_) | | | (_| __/ 8 | |_| |_|\___|_| |_| |_|\___| |_| \___/|_|_|\___\___| 9 | 10 | ''' 11 | 12 | # This is the message that users receive about illegal memes 13 | from message import message, mention, damages, bl_message 14 | # This file contains one method to input an image and output found text 15 | from text_recognition import text_recognition 16 | # Dictionary of banned words 17 | from blacklist import illegal_memes 18 | # The config file with reddit API credentials 19 | import config as config 20 | 21 | # The rude phrases reply list and function 22 | from rude_phrases import rude_list, rude_reply_list, rudeness_reply, alt_rudeness_reply 23 | 24 | # For the cooldown purposes, see below 25 | import time 26 | 27 | # For analyzing and saving comment words 28 | from analyze import parse_comment 29 | 30 | # Assorted Utilities 31 | from utils import log_to_file 32 | 33 | # Tracking iterations 34 | from tqdm import tqdm 35 | # Python Reddit API Wrapper. Self-explanatory 36 | import praw 37 | 38 | # Finding a pattern 39 | import re 40 | 41 | # Multi-threading 42 | from threading import Thread 43 | 44 | # JSON Parsing 45 | import json 46 | 47 | import random 48 | 49 | reddit = praw.Reddit(client_id=config.client_id, 50 | client_secret=config.client_secret, 51 | username=config.username, 52 | password=config.password, 53 | user_agent=config.user_agent) 54 | 55 | subreddit = reddit.subreddit('pewdiepiesubmissions') 56 | 57 | # Tesseract-OCR package can work only with jpeg, jpg, png,c gif, bmp files. Reject all other urls 58 | pattern = re.compile(".(jpe?g|png|gifv?)(\?\S*)?") 59 | 60 | 61 | # Sends a reply to users 62 | def ban(post, place, violation): 63 | print("Found an illegal word in {}!".format(place)) 64 | 65 | title = post.title.encode('utf-8').lower() 66 | 67 | file = open("./logs/violations_log.txt", 'a') 68 | file.write(str(title) + " at " + time.strftime("%b %d, %Y - %I:%M:%S") + "\n") 69 | file.close() 70 | 71 | # Save violation 72 | save_violation(violation) 73 | 74 | # Replace the text %VIOLATION% with the violating word 75 | message_to_send = message.replace("%VIOLATION%", violation) 76 | 77 | post.reply(message_to_send) 78 | 79 | 80 | def save_user(user): 81 | try: 82 | file = open("./users/users.json", 'r') 83 | users_json = json.loads(file.read()) 84 | file.close() 85 | 86 | if user in users_json.keys(): 87 | users_json[user] = int(users_json.get(user)) + 1 88 | 89 | try: 90 | file = open("./users/users.json", 'w') 91 | file.write(json.dumps(users_json)) 92 | file.close() 93 | except: 94 | log_to_file("Failed to write to users.json at " + time.strftime("%b %d, %Y - %I:%M:%S")) 95 | 96 | else: 97 | users_json[user] = 1 98 | 99 | try: 100 | file = open("./users/users.json", 'w') 101 | file.write(json.dumps(users_json)) 102 | file.close() 103 | except: 104 | log_to_file("Failed to write to users.json at" + time.strftime("%b %d, %Y - %I:%M:%S")) 105 | except: 106 | log_to_file("Failed to read users.json at" + time.strftime("%b %d, %Y - %I:%M:%S")) 107 | file = open("./users/users.json", 'w') 108 | file.write("{}") 109 | file.close() 110 | 111 | 112 | def save_violation(v): 113 | try: 114 | file = open("./violations/violations.json", 'r') 115 | violations_json = json.loads(file.read()) 116 | file.close() 117 | 118 | if v in violations_json.keys(): 119 | violations_json[v] = int(violations_json.get(v)) + 1 120 | 121 | try: 122 | file = open("./violations/violations.json", 'w') 123 | file.write(json.dumps(violations_json)) 124 | file.close() 125 | except: 126 | log_to_file("Failed to write to violations.json at" + time.strftime("%b %d, %Y - %I:%M:%S")) 127 | 128 | else: 129 | violations_json[v] = 1 130 | 131 | try: 132 | file = open("./violations/violations.json", 'w') 133 | file.write(json.dumps(violations_json)) 134 | file.close() 135 | except: 136 | log_to_file("Failed to write to violations.json at" + time.strftime("%b %d, %Y - %I:%M:%S")) 137 | except: 138 | log_to_file("Failed to read violations.json at" + time.strftime("%b %d, %Y - %I:%M:%S")) 139 | file = open("./violations/violations.json", 'w') 140 | file.write("{}") 141 | file.close() 142 | 143 | 144 | def submission_thread(): 145 | while True: 146 | for submission in tqdm(subreddit.stream.submissions()): 147 | 148 | post = reddit.submission(submission) 149 | # Sometimes the submissions' titles include non-ASCII symbols. Need to validate and encode. 150 | # All the banned words are in lowercase, that is why we need to convert it to lowercase. 151 | title = post.title.encode('utf-8').lower() 152 | 153 | checked = open("./checked.txt", 'r') 154 | check = checked.readlines() 155 | checked.close() 156 | 157 | if post.id + "\n" not in check: 158 | print("Reading Submission '" + str(title) + "' at " + time.strftime("%b %d, %Y - %I:%M:%S") + " by " + str(post.author)) 159 | 160 | checked = open("./checked.txt", "a") 161 | checked.write(post.id + "\n") 162 | checked.close() 163 | 164 | if pattern.search(post.url) is not None: 165 | print("\tMatched regex, post is an image") 166 | 167 | meme_text = "" 168 | 169 | try: 170 | meme_text = str(text_recognition(post).lower()) 171 | except Exception as e: 172 | print(e) 173 | print("\tImage Text: {}".format(meme_text)) 174 | 175 | if "bitch lasagna" in meme_text or "bitch lasagna" in str(title): 176 | message_to_send = bl_message 177 | post.reply(message_to_send) 178 | continue 179 | 180 | for word in illegal_memes: 181 | if word in meme_text: 182 | # Save user data 183 | save_user(str(post.author)) 184 | 185 | # Comment on post 186 | ban(post, "image", word) 187 | break 188 | 189 | # If not found in recognized text, analyze title 190 | elif word in str(title): 191 | # Save user data 192 | save_user(str(post.author)) 193 | 194 | # Comment on post 195 | ban(post, "image", word) 196 | break 197 | 198 | else: 199 | if "bitch lasagna" in str(title): 200 | message_to_send = bl_message 201 | post.reply(message_to_send) 202 | continue 203 | 204 | for word in illegal_memes: 205 | if word in str(title): 206 | # Save user data 207 | save_user(str(post.author)) 208 | 209 | # Comment on post 210 | ban(post, "image", word) 211 | break 212 | else: 213 | print("Already checked post, '" + str(title) + "' - skipping") 214 | time.sleep(60) 215 | 216 | 217 | def comment_thread(): 218 | while True: 219 | for c in subreddit.stream.comments(): 220 | 221 | check = open("./checked_comments.txt", 'r') 222 | checked = check.readlines() 223 | check.close() 224 | 225 | if c.id + "\n" not in checked: 226 | file = open("./checked_comments.txt", "a") 227 | file.write(c.id + "\n") 228 | file.close() 229 | 230 | if "memepolice" not in str(c.author.name.encode("utf-8").lower()): # We don't need to parse our own comments 231 | summon_bot(c) 232 | parse_comment(c) 233 | reply_to_comments(c) 234 | time.sleep(30) 235 | 236 | 237 | def reply_to_comments(c): 238 | try: 239 | text = str(c.body.encode("utf-8").lower()) # c.body is a byte-like object but we need str 240 | 241 | if "ur mom gay" in text or "your mom gay" in text: 242 | alt_rudeness_reply(c, "no u") 243 | return 244 | 245 | elif "good bot" in text: 246 | alt_rudeness_reply(c, "Good human :)") 247 | return 248 | 249 | elif "bad bot" in text: 250 | alt_rudeness_reply(c, "My creators specifically programmed me to feel physical pain when people say I'm bad. I hope you're happy :(") 251 | return 252 | 253 | elif "no u" in text: 254 | alt_rudeness_reply(c, damages[random.randint(0, len(damages) - 1)]) 255 | return 256 | 257 | for w in rude_list: 258 | if w in text: 259 | rudeness_reply(c) 260 | break 261 | 262 | except Exception as e: 263 | print("Something bad happened in reply_to_comments: {}".format(e)) 264 | 265 | 266 | def summon_bot(c): 267 | try: 268 | text = str(c.body.encode("utf-8").lower()) # c.body is a byte-like object but we need str 269 | if "u/memepolice" in text: 270 | c.reply(mention) 271 | ban(c.submission, "image", "I was called!") 272 | print("summon_bot triggered!") 273 | except Exception as e: 274 | print("Something bad happened in summon_bot: {}".format(e)) 275 | 276 | 277 | def save_karma(): 278 | memepolice = reddit.redditor("MemePolice_bot") 279 | while True: 280 | for comment in memepolice.comments.new(limit=100): 281 | # It will parse 100 comments in 5-6 seconds 282 | if comment.ups < -2: 283 | comment.delete() 284 | 285 | # 1 hour of sleep 286 | time.sleep(3600) 287 | 288 | 289 | def threads(): 290 | Thread(name="Submissions", target=submission_thread).start() 291 | Thread(name="Comments", target=comment_thread).start() 292 | Thread(name="Save Karma", target=save_karma).start() 293 | 294 | 295 | def main(): 296 | threads() 297 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------