Exemple #1
0
 def handle(self, *args, **options):
     users = User.objects.all()
     c = LightsteemClient(nodes=["https://hived.emre.sh"])
     dygp = c.get_dynamic_global_properties()
     steem_per_mvest = (
             float(Amount(dygp["total_vesting_fund_hive"]).amount) /
             (float(Amount(dygp["total_vesting_shares"]).amount) / 1e6))
     c = LightsteemClient(nodes=["https://hived.emre.sh"])
     for chunk in chunks(users, 500):
         account_details = c.get_accounts([c.username for c in chunk])
         for account_detail in account_details:
             try:
                 related_user = User.objects.get(
                     username=account_detail["name"])
             except User.DoesNotExist:
                 print(f"{account_detail['name']} is not found. Skipping.")
                 continue
             print("updating", related_user)
             related_user.update_info(
                 steem_per_mvest=steem_per_mvest,
                 account_detail=account_detail,
             )
Exemple #2
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.config = kwargs.get("dcom_config")
     self.lightsteem_client = LightsteemClient(
         nodes=self.config["steem_nodes"],
         keys=[self.config["bot_posting_key"]])
     self.community_name = self.config.get("community_name")
     self.registration_channel = self.config.get("registration_channel")
     self.registration_account = self.config.get("registration_account")
     self.role_name_for_registered_users = self.config.get(
         "role_name_for_registered_users")
     self.curation_channels = self.config.get("curation_channels")
     self.mongo_client = MongoClient(self.config.get("M0NGO_URI"))
     self.mongo_database = self.mongo_client["dcom"]
     self.patron_role = self.config.get("patron_role")
     self.bot_log_channel = self.config.get("bot_log_channel")
     self.account_for_vp_check = self.config.get("account_for_vp_check")
     self.limit_on_maximum_vp = self.config.get("limit_on_maximum_vp")
     self.bot_account = self.config.get("bot_account")
     self.auto_curation_vote_weight = 20
Exemple #3
0
def sync_vote(request):
    trx_id = request.GET.get("trx_id")

    try:
        # block numbers must be integer
        block_num = int(request.GET.get("block_num"))
    except (TypeError, ValueError):
        return HttpResponse('Invalid block ID', status=400)

    c = LightsteemClient(nodes=["https://api.hive.blog"])
    block_data = c.get_block(block_num)
    if not block_data:
        # block data may return null if it's invalid
        return HttpResponse('Invalid block ID', status=400)

    vote_tx = None
    for transaction in block_data.get("transactions", []):
        if transaction.get("transaction_id") == trx_id:
            vote_tx = transaction
            break

    if not vote_tx:
        return HttpResponse('Invalid transaction ID', status=400)

    vote_op = None
    for op_type, op_value in transaction.get("operations", []):
        if op_type != "comment":
            continue
        vote_op = op_value

    if not vote_op:
        return HttpResponse("Couldn't find valid vote operation.", status=400)

    # validate json metadata
    if not vote_op.get("json_metadata"):
        return HttpResponse("json_metadata is missing.", status=400)

    json_metadata = json.loads(vote_op.get("json_metadata", ""))

    # json_metadata should indicate content type
    if json_metadata.get("content_type") != "poll_vote":
        return HttpResponse("content_type field is missing.", status=400)

    # check votes
    votes = json_metadata.get("votes", [])
    if not len(votes):
        return HttpResponse("votes field is missing.", status=400)

    # check the poll exists
    try:
        question = Question.objects.get(
            username=vote_op.get("parent_author"),
            permlink=vote_op.get("parent_permlink"),
        )
    except Question.DoesNotExist:
        return HttpResponse("parent_author/parent_permlink is not a poll.",
                            status=400)

    # Validate the choice
    choices = Choice.objects.filter(question=question, )
    selected_choices = []
    for choice in choices:
        for user_vote in votes:
            if choice.text == user_vote:
                selected_choices.append(choice)

    if not selected_choices:
        return HttpResponse("Invalid choices in votes field.", status=400)

    # check if the user exists in our database
    # if it doesn't, create it.
    try:
        user = User.objects.get(username=vote_op.get("author"))
    except User.DoesNotExist:
        user = User.objects.create_user(username=vote_op.get("author"))
        user.save()

    # check if we already registered a vote from that user
    if Choice.objects.filter(voted_users__username=vote_op.get("author"),
                             question=question).count() != 0:
        return HttpResponse("You have already voted on that poll.", status=400)

    # register the vote
    for selected_choice in selected_choices:
        selected_choice.voted_users.add(user)

    # add vote audit entry
    vote_audit = VoteAudit(question=question,
                           voter=user,
                           block_id=block_num,
                           trx_id=trx_id)
    vote_audit.save()

    return HttpResponse("Vote is registered to the database.", status=200)
import uuid
from datetime import datetime

import discord
from dateutil.parser import parse
from discord.ext import commands
from django.conf import settings
from django.core.management.base import BaseCommand
from lightsteem.client import Client as LightsteemClient
from lightsteem.datastructures import Operation
from polls.models import Question

from .utils import get_comment_body

client = discord.Client()
lightsteem_client = LightsteemClient(keys=[settings.CURATION_BOT_POSTING_KEY],
                                     loglevel=logging.DEBUG)
bot = commands.Bot(command_prefix='$', description="dPoll curation bot")


@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


async def my_background_task():
    """
    Check the VP constantly.
    If the VP is greater than %95, then vote randomly on dpoll voters.
Exemple #5
0
def get_lightsteem_client():
    global _lightsteem_client
    if not _lightsteem_client:
        _lightsteem_client = LightsteemClient(nodes=settings.STEEM_NODE_LIST)
    return _lightsteem_client