def bayesian_score_generic(self): try: scored = antispam_external.score(self.message.content) except: scored = 0 self.bayesian_score = scored
async def spam_tracker(event): global SPAM if SPAM == True: ch = str(event.raw_text) spamscore = antispam.score(ch) spambool = antispam.is_spam(ch) if spambool == True: await event.reply('Spam Message Detected') await event.reply('Spam results for `' + ch + '`\nScore: ' + spamscore + '\nIs Spam: ' + spambool)
def is_spam(message): try: spam_score = antispam.score(message.content) if spam_score >= SPAM_THRESHOLD: logging.info('Message from %s with spam score %s', message.author, spam_score) return True else: return False except TypeError: pass except discord.errors.Forbidden as err: logging.error(str(err))
def base_post_add(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): import antispam post = form.save(commit=False) post.author = request.user post.published_date = timezone.now() post.spam_score = str(antispam.score(post.text)) post.save() return redirect('base_post', pk=post.pk) else: form = PostForm() return render(request, 'base_post_add.html', {'form': form})
async def my_e_handler(e): if '.xen ping' == e.raw_text: start=round(time.time() * 1000) pongmsg=await e.reply('Pong!') end=round(time.time() * 1000) msstartend=int(end) - int(start) await client(EditMessageRequest(peer=e.chat_id, id=pongmsg.id, message='Pong!\n' + str(msstartend) + 'ms')) elif '.msgid' == e.raw_text: await e.reply('There are ' + str(e.id + 1) + ' messages (including this one) in this chat') elif '.random' == e.raw_text: rannum = randint(0, 69420) await e.reply(str(rannum)) elif '.antispam' in e.raw_text: checkspam=str(e.raw_text[11:]) spamscore=str(antispam.score(checkspam)) spambool=str(antispam.is_spam(checkspam)) await e.reply('Spam results for `' + checkspam + '`\nScore: ' + spamscore + '\nIs Spam: ' + spambool)
def is_spam(self, text): return { 'score': antisp.score(text), 'is_spam': int(antisp.is_spam(text)) }
def check_and_insert_new_comment(name): # Get project project = db.session.query(TProjects).filter( TProjects.name == name).first() # Check refferer, this is not bullet proof if not compare_digest(request.origin, project.blogurl): return make_response(jsonify(status="not-allowed"), 403) if not project: return make_response(jsonify(status="post-project-not-found"), 400) if compare_digest(request.method, "POST"): smileys = Smileys() sender = Mail() # Check length of content and abort if too long or too short if request.content_length > 2048: return make_response(jsonify(status="post-max-length"), 400) if request.content_length == 0: return make_response(jsonify(status="post-min-length"), 400) # get json from request new_comment = request.json # save and sanitize location, nice try, bitch location = new_comment['location'].strip().replace('.', '') # Validate json and check length again if not is_valid_json(new_comment) or \ len(new_comment['content']) < 40 or \ len(new_comment['email']) < 5: return make_response(jsonify(status='post-invalid-json'), 400) # Strip any HTML from message body tags = re.compile('<.*?>') special = re.compile('[&].*[;]') content = re.sub(tags, '', new_comment['content']).strip() content = re.sub(special, '', content).strip() # Convert smileys if enabled if project.addon_smileys: for key, value in smileys.smileys.items(): content = content.replace(key, value) # Validate replied_to field is integer replied_to = new_comment['replied_to'] try: if replied_to: replied_to = int(replied_to) # not a valid id at all except ValueError: return make_response(jsonify(status="bad-reply"), 400) # Update values new_comment.update({"content": content}) new_comment.update({"email": new_comment['email'].strip()}) new_comment.update({"location": location}) new_comment.update({"replied_to": replied_to}) # Check mail if not sender.validate(new_comment['email']): return make_response(jsonify(status='post-invalid-email'), 400) # check for spam is_spam = spam(new_comment['content']) has_score = score(new_comment['content']) # Insert mail into spam if detected, allow if listed as such email = db.session.query(TEmail).filter( TEmail.email == new_comment['email']).first() if not email: if is_spam: entry = { "email": new_comment['email'], "is_blocked": True, "is_allowed": False } db.session.add(TEmail(**entry)) if email: if not email.is_allowed: is_spam = True if email.is_allowed: # This forces the comment to be not spam if the address is in the allowed list, # but the commenter will still need to confirm it to avoid brute # force attacks against this feature is_spam = False # Look for location loc_query = db.session.query(TLocation) \ .filter(TLocation.location == new_comment['location']) if loc_query.first(): # Location exists, set existing location id new_comment.update({'location_id': loc_query.first().id_location}) # TComments does not have this field new_comment.pop("location") else: # Insert new location loc_table = { 'location': new_comment['location'], 'project_id': project.id_project } new_loc = TLocation(**loc_table) db.session.add(new_loc) db.session.flush() db.session.refresh(new_loc) new_comment.update({'location_id': new_loc.id_location}) # TComments does not have this field new_comment.pop("location") # insert comment # noinspection PyBroadException try: if project.sendotp: new_comment.update({"is_published": False}) else: new_comment.update({"is_published": True}) new_comment.update({"created_on": default_timestamp()}) new_comment.update({"is_spam": is_spam}) new_comment.update({"spam_score": has_score}) new_comment.update({ "gravatar": check_gravatar(new_comment['email'], project.name) }) new_comment.update({"project_id": project.id_project}) t_comment = TComments(**new_comment) db.session.add(t_comment) db.session.commit() db.session.flush() db.session.refresh(t_comment) # Send confirmation link and store returned value if project.sendotp: hashes = sender.send_confirmation_link(new_comment['email'], project.name) setattr(t_comment, "confirmation", hashes[0]) setattr(t_comment, "deletion", hashes[1]) db.session.commit() except exc.IntegrityError as e: # Comment body exists, because content is unique print( f"Duplicate from {request.environ['REMOTE_ADDR']}, error is:\n{e}", file=stderr) return make_response(jsonify(status="post-duplicate"), 400) except Exception: # must be at bottom return make_response(jsonify(status="post-internal-server-error"), 400) export_location(t_comment.location_id) return make_response( jsonify(status="post-success", comment_id=t_comment.comments_id, sendotp=project.sendotp), 200)
for folder in folders: pp += 1 overall = emailleri_al(folder) print(overall) if (pp == 1): return overall break h = fetching() f = open('data.csv', 'w') r = dict() p = dict() for i in h: try: y = antispam.score(i.bodyc) if (i.From not in r): p[i.From] = 1 r[i.From] = y else: p[i.From] += 1 r[i.From] += y except: pass x = open('gotonetwork.csv', 'w') for i in h: try: y = antispam.score(i.bodyc) f.write("{},{},{},{},{}\n".format(str(i.From), str(i.subject), str(i.bodyc), str(y), str(r[i.From] / p[i.From])))
import antispam, sys x = " ".join(sys.argv[2:]) print(antispam.score(x))